File tree Expand file tree Collapse file tree 1 file changed +17
-1
lines changed
sources/assets/Stride.Core.Assets/Compiler Expand file tree Collapse file tree 1 file changed +17
-1
lines changed Original file line number Diff line number Diff line change 3
3
4
4
using System ;
5
5
using System . Collections . Generic ;
6
+ using System . Diagnostics ;
6
7
using System . Linq ;
7
8
using System . Reflection ;
8
9
using Stride . Core ;
@@ -181,7 +182,7 @@ private void RegisterAssembly(Assembly assembly)
181
182
private void RegisterCompilersFromAssembly ( Assembly assembly )
182
183
{
183
184
// Process Asset types.
184
- foreach ( var type in assembly . GetTypes ( ) )
185
+ foreach ( var type in GetFullyLoadedTypes ( assembly ) )
185
186
{
186
187
// Only process Asset types
187
188
if ( ! typeof ( IAssetCompiler ) . IsAssignableFrom ( type ) || ! type . IsClass )
@@ -202,6 +203,21 @@ private void RegisterCompilersFromAssembly(Assembly assembly)
202
203
log . Error ( $ "Unable to instantiate compiler [{ compilerAttribute . TypeName } ]", ex ) ;
203
204
}
204
205
}
206
+
207
+ // Taken from https://stackoverflow.com/questions/7889228/how-to-prevent-reflectiontypeloadexception-when-calling-assembly-gettypes
208
+ [ DebuggerNonUserCode ]
209
+ IEnumerable < Type > GetFullyLoadedTypes ( Assembly assembly )
210
+ {
211
+ try
212
+ {
213
+ return assembly . GetTypes ( ) ;
214
+ }
215
+ catch ( ReflectionTypeLoadException ex )
216
+ {
217
+ log . Warning ( $ "Could not load all types from assembly { assembly . FullName } ", ex ) ;
218
+ return ex . Types . Where ( t => t != null ) ;
219
+ }
220
+ }
205
221
}
206
222
207
223
private void UnregisterAssembly ( Assembly assembly )
You can’t perform that action at this time.
0 commit comments