Replacement of AssemblyBuilder.DefineDynamicAssembly in .NET Core
Asked Answered
P

1

79

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

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

Is it possible?

Polemics answered 29/4, 2016 at 11:32 Comment(0)
A
140

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>
Acrimony answered 29/4, 2016 at 11:48 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.