@@ -67,9 +67,15 @@ public List<TypeInfoModel> LoadAssemblyTypes(string asmPath)
6767 if ( type . FullName == null )
6868 continue ;
6969
70- var ti = CollectTypeInfo ( type ) ;
71-
72- result . Add ( ti ) ;
70+ try
71+ {
72+ var ti = CollectTypeInfo ( type ) ;
73+ result . Add ( ti ) ;
74+ }
75+ catch ( Exception ex )
76+ {
77+ _logger . LogWarning ( ex , "Failed to collect type info for {Type}" , type . FullName ?? type . Name ) ;
78+ }
7379 }
7480
7581 return result ;
@@ -84,74 +90,118 @@ private TypeInfoModel CollectTypeInfo(Type type)
8490 . Select ( i => i . Name )
8591 . ToList ( ) ;
8692
87- // Collect constructors with parameters
88- model . Constructors = type . GetConstructors ( BindingFlags . Public | BindingFlags . Instance )
89- . Select ( c => new ConstructorInfoModel
93+ // Collect constructors with parameters (skip broken ones)
94+ var constructors = new List < ConstructorInfoModel > ( ) ;
95+ foreach ( var ctor in type . GetConstructors ( BindingFlags . Public | BindingFlags . Instance ) )
96+ {
97+ try
9098 {
91- Name = c . Name ,
92- Parameters = c . GetParameters ( )
99+ var parameters = ctor . GetParameters ( )
93100 . Select ( p => new ParameterInfoModel
94101 {
95102 Name = p . Name ?? "" ,
96103 ParameterType = p . ParameterType . Name
97104 } )
98- . ToList ( )
99- } )
100- . ToList ( ) ;
105+ . ToList ( ) ;
101106
102- // Collect methods with parameters
103- model . Methods = type . GetMethods ( BindingFlags . Public | BindingFlags . Instance | BindingFlags . Static | BindingFlags . DeclaredOnly )
104- . Select ( m => CollectMethodInfo ( m ) )
105- . ToList ( ) ;
107+ constructors . Add ( new ConstructorInfoModel
108+ {
109+ Name = ctor . Name ,
110+ Parameters = parameters
111+ } ) ;
112+ }
113+ catch ( Exception ex )
114+ {
115+ _logger . LogWarning ( ex , "Failed to collect constructor info for {Type}::{Ctor}" , model . FullName , ctor . Name ) ;
116+ }
117+ }
118+ model . Constructors = constructors ;
119+
120+ // Collect methods with parameters (skip broken ones)
121+ var methods = new List < MethodInfoModel > ( ) ;
122+ foreach ( var m in type . GetMethods ( BindingFlags . Public | BindingFlags . Instance | BindingFlags . Static | BindingFlags . DeclaredOnly ) )
123+ {
124+ try
125+ {
126+ var mi = CollectMethodInfo ( m ) ;
127+ methods . Add ( mi ) ;
128+ }
129+ catch ( Exception ex )
130+ {
131+ _logger . LogWarning ( ex , "Failed to collect method info for {Type}::{Method}" , model . FullName , m . Name ) ;
132+ }
133+ }
134+ model . Methods = methods ;
106135
107136 // Properties (public at least on getter or setter)
108137 var props = type . GetProperties ( BindingFlags . Public | BindingFlags . Instance | BindingFlags . Static | BindingFlags . DeclaredOnly ) ;
109138 foreach ( var p in props )
110139 {
111- var getMethod = p . GetGetMethod ( /*nonPublic*/ false ) ; // only public
112- var setMethod = p . GetSetMethod ( /*nonPublic*/ false ) ; // only public
140+ try
141+ {
142+ var getMethod = p . GetGetMethod ( /*nonPublic*/ false ) ; // only public
143+ var setMethod = p . GetSetMethod ( /*nonPublic*/ false ) ; // only public
113144
114- bool hasPublicGetter = ( getMethod != null ) ;
115- bool hasPublicSetter = ( setMethod != null ) ;
145+ bool hasPublicGetter = ( getMethod != null ) ;
146+ bool hasPublicSetter = ( setMethod != null ) ;
116147
117- // If there is neither a public getter nor a public setter, skip
118- if ( ! hasPublicGetter && ! hasPublicSetter )
119- continue ;
148+ // If there is neither a public getter nor a public setter, skip
149+ if ( ! hasPublicGetter && ! hasPublicSetter )
150+ continue ;
120151
121- var propModel = CollectPropertyInfo ( p ) ;
122- model . Properties . Add ( propModel ) ;
152+ var propModel = CollectPropertyInfo ( p ) ;
153+ model . Properties . Add ( propModel ) ;
154+ }
155+ catch ( Exception ex )
156+ {
157+ _logger . LogWarning ( ex , "Failed to collect property info for {Type}::{Property}" , model . FullName , p . Name ) ;
158+ }
123159 }
124160
125161 // Fields (only public)
126162 var fields = type . GetFields ( BindingFlags . Public | BindingFlags . Instance | BindingFlags . Static | BindingFlags . DeclaredOnly ) ;
127163 foreach ( var f in fields )
128164 {
129- if ( ! f . IsPublic )
130- continue ; // although GetFields(Public) already excludes non-public, just in case
131- var fi = CollectFieldInfo ( f ) ;
132- model . Fields . Add ( fi ) ;
165+ try
166+ {
167+ if ( ! f . IsPublic )
168+ continue ; // although GetFields(Public) already excludes non-public, just in case
169+ var fi = CollectFieldInfo ( f ) ;
170+ model . Fields . Add ( fi ) ;
171+ }
172+ catch ( Exception ex )
173+ {
174+ _logger . LogWarning ( ex , "Failed to collect field info for {Type}::{Field}" , model . FullName , f . Name ) ;
175+ }
133176 }
134177
135178 // Events (public)
136179 var events = type . GetEvents ( BindingFlags . Public | BindingFlags . Instance | BindingFlags . Static | BindingFlags . DeclaredOnly ) ;
137180 foreach ( var e in events )
138181 {
139- if ( e . EventHandlerType == null )
140- continue ; // should not happen
141-
142- // If public add/remove methods
143- var addM = e . GetAddMethod ( false ) ;
144- var removeM = e . GetRemoveMethod ( false ) ;
145- if ( addM == null && removeM == null )
146- continue ;
182+ try
183+ {
184+ if ( e . EventHandlerType == null )
185+ continue ; // should not happen
186+
187+ // If public add/remove methods
188+ var addM = e . GetAddMethod ( false ) ;
189+ var removeM = e . GetRemoveMethod ( false ) ;
190+ if ( addM == null && removeM == null )
191+ continue ;
147192
148- var ei = new EventInfoModel
193+ var ei = new EventInfoModel
194+ {
195+ Name = e . Name ,
196+ EventHandlerType = GetFriendlyName ( e . EventHandlerType ) ,
197+ IsStatic = ( addM ? . IsStatic ?? false ) || ( removeM ? . IsStatic ?? false )
198+ } ;
199+ model . Events . Add ( ei ) ;
200+ }
201+ catch ( Exception ex )
149202 {
150- Name = e . Name ,
151- EventHandlerType = GetFriendlyName ( e . EventHandlerType ) ,
152- IsStatic = ( addM ? . IsStatic ?? false ) || ( removeM ? . IsStatic ?? false )
153- } ;
154- model . Events . Add ( ei ) ;
203+ _logger . LogWarning ( ex , "Failed to collect event info for {Type}::{Event}" , model . FullName , e . Name ) ;
204+ }
155205 }
156206
157207 return model ;
0 commit comments