d--b
d--b

Reputation: 5779

Updating solution to .net framework 4.7: issue with Roslyn

I'm trying to update a solution that uses roslyn to 4.7. When updating the nuget packages I get the following error:

One or more unresolved package dependency constraints detected in the existing packages.config file. All dependency constraints must be resolved to add or update packages. If these packages are being updated this message may be ignored, if not the following error(s) may be blocking the current package operation: 'System.Security.Cryptography.Algorithms 4.3.0 constraint: System.IO (>= 4.3.0)'

And then, when trying to use Roslyn, I get an exception running the following code:

var compilation = CSharpCompilation.Create("MyCompilation", new[] {syntaxTree}, references);
var diag = compilation.GetDiagnostics();

The Exception is:

Managed Debugging Assistant 'BindingFailure' occurred HResult=0x00000000 Message=Managed Debugging Assistant 'BindingFailure' : 'The assembly with display name 'System.Security.Cryptography.Algorithms' failed to load in the 'LoadFrom' binding context of the AppDomain with ID 1. The cause of the failure was: System.IO.FileLoadException: Could not load file or assembly 'System.Security.Cryptography.Algorithms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)'

Any idea about how to fix?

Upvotes: 2

Views: 1786

Answers (2)

d--b
d--b

Reputation: 5779

Turns out the issue was with the dependent assembly redirection. It looks like VS2017 adds a lot of these all over my app.config files.

Changing:

  <dependentAssembly>
    <assemblyIdentity name="System.Security.Cryptography.Algorithms" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
    <bindingRedirect oldVersion="0.0.0.0-4.2.1.0" newVersion="4.2.1.0" />
  </dependentAssembly>

with this:

  <dependentAssembly>
    <assemblyIdentity name="System.Security.Cryptography.Algorithms" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
    <bindingRedirect oldVersion="0.0.0.0-4.2.1.0" newVersion="4.1.0.0" />
  </dependentAssembly>

in my main project app.config file seems to have done it.

Upvotes: 2

Dudi Keleti
Dudi Keleti

Reputation: 2984

You may want to show us the contents of the packages.config file. From what its looks like you need to upgrade System.IO to version 4.3.0 or higher, because System.Security.Cryptography.Algorithms requires it.

Upvotes: 0

Related Questions