@@ -155,6 +155,12 @@ internal static Task<IUnresolvedAssembly> LoadModuleAsync(Module module, ICorDeb
155155 string name = corModule . GetName ( ) ;
156156 if ( corModule . IsDynamic ( ) == 1 || corModule . IsInMemory ( ) == 1 ) {
157157 var defaultUnresolvedAssembly = new DefaultUnresolvedAssembly ( name ) ;
158+ var defaultUnresolvedTypeDefinition = new DefaultUnresolvedTypeDefinition ( "UnknownDynamicType" ) ;
159+ var defaultUnresolvedMethod = new DefaultUnresolvedMethod ( defaultUnresolvedTypeDefinition , "UnknownMethod" ) ;
160+ var defaultUnresolvedField = new DefaultUnresolvedField ( defaultUnresolvedTypeDefinition , "UnknownField" ) ;
161+ defaultUnresolvedTypeDefinition . Members . Add ( defaultUnresolvedMethod ) ;
162+ defaultUnresolvedTypeDefinition . Members . Add ( defaultUnresolvedField ) ;
163+ defaultUnresolvedAssembly . AddTypeDefinition ( defaultUnresolvedTypeDefinition ) ;
158164 weakTable . Add ( defaultUnresolvedAssembly , new ModuleMetadataInfo ( module , null ) ) ;
159165 return Task . FromResult < IUnresolvedAssembly > ( defaultUnresolvedAssembly ) ;
160166 }
@@ -527,6 +533,9 @@ public static IMethod Import(this ICompilation compilation, ICorDebugFunction co
527533 public static IMethod Import ( this ICompilation compilation , ICorDebugFunction corFunction )
528534 {
529535 Module module = compilation . GetAppDomain ( ) . Process . GetModule ( corFunction . GetModule ( ) ) ;
536+ if ( module . IsDynamic || module . IsInMemory ) {
537+ return module . Assembly . GetTypeDefinition ( "" , "UnknownDynamicType" ) . Methods . First ( ) ;
538+ }
530539 var info = GetInfo ( module . Assembly ) ;
531540 uint functionToken = corFunction . GetToken ( ) ;
532541 var unresolvedMethod = info . GetMethodFromToken ( functionToken ) ;
@@ -547,6 +556,9 @@ public static IMethod Import(this ICompilation compilation, ICorDebugFunction co
547556 public static IField ImportField ( this IType declaringType , uint fieldToken )
548557 {
549558 var module = declaringType . GetDefinition ( ) . ParentAssembly . GetModule ( ) ;
559+ if ( module . IsDynamic || module . IsInMemory ) {
560+ return module . Assembly . GetTypeDefinition ( "" , "UnknownDynamicType" ) . Fields . First ( ) ;
561+ }
550562 var info = GetInfo ( module . Assembly ) ;
551563 return declaringType . GetFields ( f => info . GetMetadataToken ( f ) == fieldToken , GetMemberOptions . IgnoreInheritedMembers ) . SingleOrDefault ( ) ;
552564 }
0 commit comments