简体   繁体   中英

A first chance exception of type 'System.IO.FileNotFoundException' occurred in System.Net.Http.Formatting.dll

Using nuget I installed both System.Net.Http.Formatting.dll and Newtonsoft.Json.dll

<package id="Newtonsoft.Json" version="8.0.3" targetFramework="net45" />

A first chance exception of type 'System.IO.FileNotFoundException' occurred in System.Net.Http.Formatting.dll

Additional information: Could not load file or assembly 'Newtonsoft.Json, Version=4.5.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' or one of its dependencies. The system cannot find the file specified.

NOTE : Newtonsoft.Json with version="8.0.3" is already is in use. So how to include two Newtonsoft.Json versions ??

because as error is stating that System.Net.Http.Formatting.dll doesn't find the Newtonsoft.Json with version 4.5.0.0

In order to make this, you've to add one of dll in to a folder named V-1 inside bin folder. Then made config changes like this, (Place the appropriate values for labels in <> eg AssemblyName, Version-1 etc.)

<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
    <dependentAssembly>        
    <assemblyIdentity name="<AssemblyName>" publicKeyToken="<PublicKeyToken>" culture="neutral" />
        <codeBase version="<Version-1>" href="V-1\<AssemblyName>.dll" />
        <codeBase version="<Version-2>" href="<AssemblyName>.dll" />
    </dependentAssembly>      
</assemblyBinding>

Then,

  1. Please open Solution Explorer in visual studio
  2. Open References under the project
  3. Select Newtsoft reference and go to its properties.
  4. Set Specific Version = True and Copy Local = False
  5. Make sure your output directory does not contain this dll in it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM