You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[netcoreapp2.0] AssemblyLoadContext.GetLoadContext crashes when pass in a dynamic assembly #21386
AssemblyLoadContext.GetLoadContext crashes the running program when a dynamic assembly is passed in as an argument.
Repro
using System;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.Loader;
namespace Sample
{
class Program
{
static void Main(string[] args)
{
AssemblyName aName = new AssemblyName("Microsoft.PowerShell.Cmdletization.GeneratedTypes");
AssemblyBuilder ab = AssemblyBuilder.DefineDynamicAssembly(aName, AssemblyBuilderAccess.Run);
ModuleBuilder mb = ab.DefineDynamicModule(aName.Name);
string fullEnumName = "Microsoft.PowerShell.Cmdletization.GeneratedTypes.TestEnum";
Type underlyingType = typeof(Int32);
EnumBuilder eb = mb.DefineEnum(fullEnumName, TypeAttributes.Public, underlyingType);
eb.DefineLiteral("Single", 0);
eb.DefineLiteral("Multiple", 1);
TypeInfo ti = eb.CreateTypeInfo();
Console.WriteLine("Dynamic assembly emitted: {0}", ti.Assembly.FullName);
var loadContext = AssemblyLoadContext.GetLoadContext(ti.Assembly);
Console.WriteLine("Yay"); // <---- program crashes and this line never executes
}
}
}
Expected behavior
The default load context should be returned by AssemblyLoadContext.GetLoadContext
Actual behavior
d:\cmdlet\Sample>dotnet run
Dynamic assembly emitted: Microsoft.PowerShell.Cmdletization.GeneratedTypes, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
d:\cmdlet\Sample>
Activity
gkhanna79 commentedon Apr 26, 2017
Issue moved to dotnet/coreclr dotnet/runtime#18350 via ZenHub