9

When we installed a previous version the Neo4jClient via nuget we saw that Newtonsoft.Json version 4.5.0.0 was installed as a dependency. We also use other packages that require version 6.0.0.0 of Newtonsoft.Json and when we install them it overrides version 4.5.0.0.

When we start our app we get this error:

Unhandled Exception: System.ServiceModel.FaultException`1[System.ServiceModel.Ex
ceptionDetail]: Could not load file or assembly 'Newtonsoft.Json, Version=4.5.0.
0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' or one of its dependencies.
The located assembly's manifest definition does not match the assembly referenc
e. (Exception from HRESULT: 0x80131040)

We looked at all our configs and found nothing referencing version 4.5.0.0, however after taking a closer look at the Neo4jClient we found this.

using ildasm.exe from visual studion tools

Here is the packages.config

<?xml version="1.0" encoding="utf-8"?>
<packages>
  <package id="AzureStorageClient" version="0.0.5.1829" targetFramework="net45" />
  <package id="CouchbaseNetClient" version="1.3.4" targetFramework="net45" />
  <package id="Elasticsearch.Net" version="1.0.0-beta1" targetFramework="net45" />
  <package id="Microsoft.Bcl" version="1.1.8" targetFramework="net45" />
  <package id="Microsoft.Bcl.Build" version="1.0.14" targetFramework="net45" />
  <package id="Microsoft.Net.Http" version="2.2.20" targetFramework="net45" />
  <package id="Neo4jClient" version="1.0.0.652" targetFramework="net45" />
  <package id="NEST" version="1.0.0-beta1" targetFramework="net45" />
  <package id="Newtonsoft.Json" version="6.0.2" targetFramework="net45" />
</packages>

We have removed all packages, reinstalled, cleaned and rebuilt but with no avail. Is this the Neo4jClient that is causing this to happen or does the problem live somewhere else?

UPDATE What we have tried

  1. Removed all packages and re installed
  2. Cleaned and rebuilt solution
  3. Assembly redirect
  4. Tried looking for <AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects> but was not in the .csproj
Mike Barnes
  • 4,217
  • 18
  • 40
  • 64

1 Answers1

11

Have you tried assembly version redirect via app.config/web.config?

<runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
        <dependentAssembly>
            <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
            <bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
        </dependentAssembly>
    </assemblyBinding>
</runtime>
Christoph Fink
  • 22,727
  • 9
  • 68
  • 113
  • Yes, funny thing though is that I have two projects in the solution. One being the code and the other the tests. The tests added a `app.config` and the main project only has a `packages.config`, which does not include the ``. – Mike Barnes Apr 24 '14 at 13:08
  • Then try to add the app.config/web.config file manually and paste the redirect in there? – Christoph Fink Apr 24 '14 at 13:27
  • While this might be an answer to my case, it does not explain WHY? Why do I need to do binding-redirect voodoo? I'll try it now... – Lzh Jun 25 '14 at 06:35
  • 1
    @Mzn: This is required, because some referenced projects (`Neo4jClient` in the OPs case) rewuired an older version of the `Newtonsoft.Json` library, but as you can not load two different versions the "old reference" is "redirected to the new version". – Christoph Fink Jun 25 '14 at 06:47
  • If adding the assemblyBinding didn't work, make sure that your web.config's configuration tag (at the top) does NOT contain the xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0" attribute. – Alucardz Sep 22 '15 at 09:00