Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where are the MethodBuilder, ModuleBuilder and AssemblyBuilder in dotnet core?

I am migrating a .Net Framework library to .Net standard and the compiler cannot find the core builders from System.Reflection.Emit.

If I am in the right place then the API documentation states that these builders (MethodBuilder, ModuleBuilder and AssemblyBuilder) are part of System.Reflection.Emit.

This is the project.json for my library:

{
  "version": "1.0.0-*",
  "buildOptions": {
    "debugType": "portable"
  },
  "dependencies": {},
  "frameworks": {
    "netstandard1.6": {
      "dependencies": {
        "NETStandard.Library": "1.6.0"
      }
    }
  }
}

Do I need any additional reference?

like image 287
Miguel Gamboa Avatar asked Feb 06 '17 19:02

Miguel Gamboa


Video Answer


2 Answers

You can find them in "System.Reflection.Emit": "4.3.0" nugget package for the netstandard1.6 framework.

like image 183
animalito maquina Avatar answered Nov 21 '22 20:11

animalito maquina


The "animalito maquina" answer also worked for me but I have investigated the problem a little bit using netstandard2.0. It might not be relevant to this question but I wanted to share this with you since it still might help others :).

I generated two projects(dotnet new):

  • "classlib" which uses netstandard2.0 on default
  • ...and "console" which uses the netcoreapp2.0

I added references to AssemblyBuilder class in both projects. The AssemblyBuilder was missing in "classlib" project that has been using netstandard2.0 but was available in "console" project - netcoreapp2.0.

The "problem" is caused by the fact that .NET Core Libraries are actually always a superset of the APIs defined in the corresponding version of the .NET Standard. There are always types and members available in the .NET Core Libraries, which are not (yet?) part of the .NET Standard.

These links might be helpful:

  • https://github.com/dotnet/standard/tree/master/docs/comparisons
  • Advantages of netcoreapp2.0 vs netstandard2.0 for a library project
  • https://github.com/dotnet/standard/blob/master/docs/comparisons/netstandard2.0_vs_netcoreapp2.0/README.md
  • https://github.com/dotnet/cli/issues/7335
like image 41
Spec Avatar answered Nov 21 '22 21:11

Spec