4

I have a service that was sending bad DateTime data due to use of the JavascriptSerializer. I used Nuget to add Newtonsoft to the project, and utilized that. Here's the only place it's utilized in the code (old way, then new):

374 
-            var messageString = new JavaScriptSerializer().Serialize(messageDetails);

374 
+            var messageString = Newtonsoft.Json.JsonConvert.SerializeObject(messageDetails);

Below is an error that occurs during the Team City build:

Consumer\MetricTrackingMQServiceConsumer.cs(374, 49): error CS0122: 'Newtonsoft.Json.JsonConvert' is inaccessible due to its protection level 
Consumer\MetricTrackingMQServiceConsumer.cs(374, 61): error CS0117: 'Newtonsoft.Json.JsonConvert' does not contain a definition for 'SerializeObject'

The project compiles fine locally. Why is it failing in Team City?

333Matt
  • 1,124
  • 2
  • 19
  • 29
  • 4
    I'm going to guess that the DLL wasn't checked into source control. Visual Studio plug in doesn't automatically try to pull in dependencies into source control (Which makes sense, they might be in Program Files, the GAC, or who knows where, it would be a real mess if VS tried to check in the Program Files folder) – MatthewMartin Jun 09 '14 at 18:25
  • This is almost certainly the case, thank you @MatthewMartin – 333Matt Jun 09 '14 at 19:39

2 Answers2

3

As you're using NuGet to include the dependency here's the workflow I strongly suggest to avoid these type of issues.

  1. Ensure that your reference to the Newtonsoft DLL is pointing at the NuGet packages folder.
  2. Exclude the NuGet packages from source control.
  3. Add a "Nuget Installer" type build step before your solution build step to restore all the NuGet packages referenced by the solution.

This has a number of advantages but most importantly given your current issue, it ensures that the version of the DLL referenced by your solution is available and in the correct location.

Paul Hunt
  • 3,395
  • 2
  • 24
  • 39
0

The following steps fixed this for me:

  1. On your nuget installer step in your build: You may need to "Disable looking up packages from local machine cache"

  2. Uninstall the newtonsoft reference via nuget in your project. Open the csproj file in a text editor and manually delete any remaining references to newtonsoft in there. Save the csproj file, reload your project

  3. Reinstall newtonsoft via nuget

  4. post your changes to your repository (git or whatever you have)

  5. Rerun the teamcity build