1

I believe this is not the same question as this for a couple of reason

  1. There was no upgrading
  2. I tried doing the x86 and x64 build and that did not work
  3. The current versions of for newtorn.JSON are 4.5

First time working with TeamCity. The ASPNETCOMPILIER cannot load the assembly for 'Newtonsoft.json'

enter image description here

I do not know how to handle this. Some key points

  • NewtonSoft is in the packages folder
  • When restoring refences this could not be resolved enter image description here
Franco Pettigrosso
  • 4,056
  • 2
  • 20
  • 32
  • Error message is pretty clear, you have something dependent on `Newtonsoft.Json 12.0.0.0`. – mxmissile Nov 11 '19 at 18:34
  • You could try just downloading the `Newtonsoft.Json.dll` manually from https://github.com/JamesNK/Newtonsoft.Json/releases and copy it to the BIN folder of the site. – VDWWD Nov 12 '19 at 11:29
  • Have you checked the exact version of the .dll on the packages folder and the version your project is dependent on? – Priyan Perera Nov 13 '19 at 02:35
  • How do your TC's build steps look like? – Mahdi Nov 15 '19 at 09:25

2 Answers2

0

You're probably using indirect multiple versions of NewtonSoft.Json. As there can be only one version in the bin folder and NewtonSoft.Json is strong named, you will get "Could not load file or assembly" errors runtime.

Solution is then to use the version 12 of NewtonSoft.Json also in your ASP.NET project, so version 12 could be loaded. It's recommend to update NewtonSoft.Json with NuGet.

If you still get load errors then with other version number, then also add to your config (if not done by nuget):

<runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
        <dependentAssembly>
            <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30AD4FE6B2A6AEED" culture="neutral"/>
            <bindingRedirect oldVersion="0.0.0.0-12.0.0.0" newVersion="12.0.0.0"/>
        </dependentAssembly>
    </assemblyBinding>
</runtime>
Julian
  • 33,915
  • 22
  • 119
  • 174
0

I've encountered this sort of issues more times than I like to admit and I've been doing this for a while now, so don't feel bad. Each time it's something small that really should not be an issue. Patience is required and is good for any developer to be reminded of.

  • In web projects changing the target CPU does not always change the values where it's supposed to. It's probably a bug. But what you can do is go into the project file itself and check for cases of "any cpu" and explicitly change any occurrence to x64.
  • If that fails make sure all your references use the the most up to date version of the framework (and target cpu if applicable) required for the newtonsoft library, although I think 4.5 is fine.
  • Create a blank project and see if you can install the library there and have it compile correctly, less stuff in a project will make it easier to troubleshoot.
  • Lastly, turn on full debugging with verbose output, you might get some more detail if you haven't already done that.

The best way I've found to resolve these issues is to isolate the problem by recreating the conditions I believe exist. When creating a new project, often I'm able to assess what's changed or missing. In the case of the target CPU, I knew it could only have been a mismatch since none of my code was present when I tested it in a fresh project.

Middletone
  • 4,190
  • 12
  • 53
  • 74