[mono] Fix AssemblyLoadContext.GetRuntimeAssembly() for AssemblyBuilders (#36367)
authorAlexis Christoforides <alexis@thenull.net>
Mon, 18 May 2020 12:46:49 +0000 (08:46 -0400)
committerGitHub <noreply@github.com>
Mon, 18 May 2020 12:46:49 +0000 (08:46 -0400)
src/mono/netcore/System.Private.CoreLib/src/System/Runtime/Loader/AssemblyLoadContext.Mono.cs

index 0fea776..5e58b1b 100644 (file)
@@ -7,6 +7,7 @@ using System.Reflection;
 using System.Runtime.CompilerServices;
 using System.Runtime.InteropServices;
 using System.Threading;
+using Internal.Runtime.CompilerServices;
 
 namespace System.Runtime.Loader
 {
@@ -155,15 +156,13 @@ namespace System.Runtime.Loader
             dll = context.GetResolvedUnmanagedDll(assembly, unmanagedDllName);
         }
 
-        #region Copied from AssemblyLoadContext.CoreCLR.cs, modified until our AssemblyBuilder implementation is functional
         private static RuntimeAssembly? GetRuntimeAssembly(Assembly? asm)
         {
             return
                 asm == null ? null :
                 asm is RuntimeAssembly rtAssembly ? rtAssembly :
-                //asm is System.Reflection.Emit.AssemblyBuilder ab ? ab.InternalAssembly :
+                asm is System.Reflection.Emit.AssemblyBuilder ab ? Unsafe.As<RuntimeAssembly>(ab) : // Mono AssemblyBuilder is also a RuntimeAssembly, see AssemblyBuilder.Mono.cs
                 null;
         }
-        #endregion
     }
 }