82

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

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

Is it possible?

1 Answer 1

145

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>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.