1

Using Visual Studio 2017 (15.3.2)

  • Create a .NET Framework class library (4.6.2)
  • Add NuGet Microsoft.EntityFrameworkCore 2.0

You get invalid references to System.Reflection and others.

enter image description here

I can compile, however, in more complicated scenarios when I'm using some functionality of Entity Framework, I am getting run-time exceptions of missing standard System.* libs.

I tried adding the NetStandard.Library first then adding the Entity Framework Core 2 after, but I got the same problem.

I have to use a .NET Framework (Class Lib) as this is a unit test project that is referencing ASP.NETCore2/NETFramework website.

Any clue of what I should be doing?

ekad
  • 14,436
  • 26
  • 44
  • 46
Adam
  • 3,872
  • 6
  • 36
  • 66
  • Could you try if the csproj file modifications from my answer here work?: https://stackoverflow.com/a/43996389/784387 – Martin Ullrich Aug 28 '17 at 17:58
  • @MartinUllrich that worked, thank you and the application is running, however, I am getting a warning regarding the references. I am also wondering if there is a better way as having all these references doesn't look natural. – Adam Aug 28 '17 at 19:01
  • It would help if you posted the actual warnings that msbuild emits (output window or output from a console build) – Martin Ullrich Aug 28 '17 at 19:11
  • @MartinUllrich it was a simple "reference not found", however, when I applied your suggestion, it is working but I am getting: Microsoft.Common.CurrentVersion.targets(2099,5): warning MSB3836: The explicit binding redirect on "System.Runtime, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" conflicts with an autogenerated binding redirect. Consider removing it from the application configuration file or disabling autogenerated binding redirects. The build will replace it with: "". – Adam Aug 28 '17 at 19:51
  • so, does doing what the warning says help? removing the binding redirects from your App.config since they are no longer necessary? – Martin Ullrich Aug 29 '17 at 04:19
  • wrote it up as an answer – Martin Ullrich Aug 29 '17 at 05:16

1 Answers1

4

This can be fixed by letting MSBuild autogenerate the necessary binding redirects by explicitly setting these two properties inside the csproj file (You can put the <ItemGroup> as a child element below the root <Project> element or add to an exiting <ItemGroup> without a Condition= attribute):

<PropertyGroup>
  <AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
  <GenerateBindingRedirectsOutputType>true</GenerateBindingRedirectsOutputType>
</PropertyGroup>

Note that this may issue warnings if you already have an App.config containing binding redirects. you can remove these redirects.

Martin Ullrich
  • 94,744
  • 25
  • 252
  • 217