1
1
using System ;
2
+ using System . IO ;
2
3
using System . Reflection ;
3
4
4
5
namespace XmlStorage . Components . Data
@@ -126,24 +127,27 @@ private Type GetType(string typeName)
126
127
}
127
128
128
129
// If the TypeName is a full name, then we can try loading the defining assembly directly
129
- if ( typeName . Contains ( "." ) )
130
+ if ( typeName . Contains ( "." ) == true )
130
131
{
131
132
// Get the name of the assembly (Assumption is that we are using
132
133
// fully-qualified type names)
133
134
var assemblyName = typeName . Substring ( 0 , typeName . IndexOf ( '.' ) ) ;
134
135
135
136
// Attempt to load the indicated Assembly
136
- var assembly = Assembly . Load ( assemblyName ) ;
137
- if ( assembly == null )
137
+ try
138
138
{
139
- return null ;
140
- }
139
+ var assembly = Assembly . Load ( assemblyName ) ;
141
140
142
- // Ask that assembly to return the proper Type
143
- type = assembly . GetType ( typeName ) ;
144
- if ( type != null )
141
+ // Ask that assembly to return the proper Type
142
+ type = assembly . GetType ( typeName ) ;
143
+ if ( type != null )
144
+ {
145
+ return type ;
146
+ }
147
+ }
148
+ catch ( SystemException e ) when ( e is FileNotFoundException || e is NullReferenceException )
145
149
{
146
- return type ;
150
+ return null ;
147
151
}
148
152
}
149
153
@@ -153,19 +157,22 @@ private Type GetType(string typeName)
153
157
154
158
foreach ( var assemblyName in referencedAssemblies )
155
159
{
156
- // Load the referenced assembly
157
- var assembly = Assembly . Load ( assemblyName ) ;
158
-
159
- if ( assembly != null )
160
+ try
160
161
{
162
+ // Load the referenced assembly
163
+ var assembly = Assembly . Load ( assemblyName ) ;
164
+
161
165
// See if that assembly defines the named type
162
166
type = assembly . GetType ( typeName ) ;
163
-
164
167
if ( type != null )
165
168
{
166
169
return type ;
167
170
}
168
171
}
172
+ catch ( SystemException e ) when ( e is FileNotFoundException || e is NullReferenceException )
173
+ {
174
+ continue ;
175
+ }
169
176
}
170
177
171
178
// The type just couldn't be found...
0 commit comments