Mscorlib unable to find dependencies throwing FileLoadException

0

I have a webApi project that was throwing an exception about being unable to find System.Diagnostics.DiagnosticSource library. I Added reference to the nuget packages with this file. But now I'm getting:

System.IO.FileLoadException: 'Could not load file or assembly 'System.Diagnostics.DiagnosticSource, Version=4.0.2.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)'

Version I have in "packages" folder is 4.6.25519.03

How do i fix this issue?

csproj reference:

    <Reference Include="System.Diagnostics.DiagnosticSource, Version=4.0.2.1, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
  <SpecificVersion>False</SpecificVersion>
  <HintPath>..\..\packages\System.Diagnostics.DiagnosticSource.4.4.1\lib\net46\System.Diagnostics.DiagnosticSource.dll</HintPath>
    </Reference>
c#
exception-handling
asked on Stack Overflow Aug 16, 2018 by AnKing • edited Aug 16, 2018 by AnKing

1 Answer

1

The Version attribute does not have to match the version number in the packages folder for that package. In fact mine are set to

<Reference Include="System.Diagnostics.DiagnosticSource, Version=4.0.3.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
  <HintPath>..\packages\System.Diagnostics.DiagnosticSource.4.5.0\lib\net46\System.Diagnostics.DiagnosticSource.dll</HintPath>
</Reference>

and the product version on the assembly is set to 4.6.26515.6 and I don't get any errors or warnings during compilation and the assembly is found at runtime.

What I suggest is

  • Update the package (it appears you're using an older version).
  • Check for other referenced versions against all your projects. Sometimes there will be multiple versions because someone managed packages at a project rather than a solution level.
  • Check the dependencies of your other NuGet packages; it's possible they are referencing other versions and this is causing the .NET assembly probing to try and load the wrong version. You can use the AssemblyBinding Log Viewer to try and diagnose this. Also, try updating those packages.

If these don't help, consider adding a binding redirect to your app.config file.

answered on Stack Overflow Aug 16, 2018 by Kit

User contributions licensed under CC BY-SA 3.0