NET Framework project can't load assembly when referencing .NET Standard project

0

I have a .NET Framework Web project which references a .NET Standard class library.

When running the app I get:

"Could not load file or assembly 'System.Net.NameResolution, Version=4.0.0.0"

So I added the System.Net.NameResolution 4.3.0 nuget package to both of these projects.

I can't use package 4.0.0 as this would be a downgrade, so I added a binding redirect to the .NET Framework project:

  <dependentAssembly>
    <assemblyIdentity name="System.Net.NameResolution" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
    <bindingRedirect oldVersion="0.0.0.0-4.0.1.0" newVersion="4.0.1.0" />
  </dependentAssembly>

The app now acknowledges my redirect, but I still get the same error:

Could not load file or assembly 'System.Net.NameResolution, Version=4.0.0.0

Calling assembly : EnyimMemcachedCore, Version=1.1.1.11, Culture=neutral, PublicKeyToken=null.

LOG: This bind starts in default load context.
LOG: Using application configuration file: C:\Source\myapp\src\Web\web.config
LOG: Using host configuration file: C:\Users\fraserb\Documents\IISExpress\config\aspnet.config
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config.
LOG: Redirect found in application configuration file: 4.0.0.0 redirected to 4.0.1.0.
LOG: Post-policy reference: System.Net.NameResolution, Version=4.0.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
LOG: Attempting download of new URL file:///C:/Windows/Microsoft.NET/Framework/v4.0.30319/Temporary ASP.NET Files/vs/31e1be3d/fde97fa5/System.Net.NameResolution.DLL.
LOG: Attempting download of new URL file:///C:/Windows/Microsoft.NET/Framework/v4.0.30319/Temporary ASP.NET Files/vs/31e1be3d/fde97fa5/System.Net.NameResolution/System.Net.NameResolution.DLL.
LOG: Attempting download of new URL file:///C:/Source/myapp/src/Web/bin/System.Net.NameResolution.DLL.
WRN: Comparing the assembly name resulted in the mismatch: Build Number
ERR: Failed to complete setup of assembly (hr = 0x80131040). Probing terminated.

Where have I gone wrong?

c#
.net-core
.net-standard
asked on Stack Overflow Jan 31, 2019 by FBryant87 • edited Jan 31, 2019 by FBryant87

1 Answer

0

Turns out binding redirect newVersion should have targeted 4.0.2.0 rather than 4.0.1.0, and everything loaded successfully after that.

(I realised it was 4.0.2.0 after double checking the version of the DLL being loaded - you can view this in Assembly Explorer)

answered on Stack Overflow Jan 31, 2019 by FBryant87

User contributions licensed under CC BY-SA 3.0