73

How do I port the following code to .NET Core?

AppDomain.CurrentDomain.DefineDynamicAssembly(
                new AssemblyName(
                    Guid.NewGuid().ToString()),
                    AssemblyBuilderAccess.RunAndSave);

Is it possible?

Pang
  • 9,564
  • 146
  • 81
  • 122
MaGu
  • 1,125
  • 2
  • 11
  • 14

1 Answers1

130

Add this to your project.json:

"dependencies": {
    "System.Reflection.Emit": "4.0.1"
 },

and use:

AssemblyBuilder.DefineDynamicAssembly(new AssemblyName(Guid.NewGuid().ToString()),
            AssemblyBuilderAccess.Run);

AssemblyBuilderAccess.RunAndSave is not supported at the moment - link to source.


For new .csproj projects, use:

<ItemGroup>
  <PackageReference Include="System.Reflection.Emit" Version="4.3.0" />
</ItemGroup>
Mike
  • 3,766
  • 3
  • 18
  • 32