Cannot compile project when replacing Json.NET link with source code

I have an ASP.NET Core 1.0 class library that I recently successfully upgraded to RTM.NET Core 1.0. I use it to implement some custom Json input and output formatter for inclusion in the ASP.NET kernel pipeline and therefore refer to the Newtonsoft.Json 9.0.1 package to work with things like the JsonSerializerSettings object. The project compiles without errors.

However, I am having some run-time problems that I want to continue to investigate by going through the Newtonsoft source code. In .NET Core, I got used to the flexibility of replacing a link to a Nuget package with source code by simply adding a link to the extracted source in the global.json file (as this blog post explains well). This works great with things like github's Microsoft AspNetCore source files, and I use them regularly.

For some reason, I cannot achieve this using the Newtonsoft source code. I cloned the Newtonsoft source code from github and checked the exact tag 9.0.1, which refers to my project. Then I added the source location to my global.json file in my solution. After that, Visual Studio 2015 immediately finds the Newtonsoft project and successfully solves it as a local link. I even see in my project links that the icon for the Newtonsoft link has changed the same way as when using the project from the same solution instead of the dll from the nuget server. In addition, I do not see any warnings or errors that you sometimes find if links are not resolved properly.

However, when I try to compile the project, now I get the following compilation error:

Error CS0012 The type "JsonSerializer" is defined in an assembly that is not referenced. You should add a link to the assembly "Newtonsoft.Json, Version = 9.0.0.0, Culture = neutral, PublicKeyToken = 30ad4fe6b2a6aeed".

The error does not make any sense to me, since links to projects are resolved without errors, and if I delete the link to the source and let it compile the version from nuget, the project compiles fine. This is the .json project of my project:

{ "version": "0.2.0", "description": "...", "authors": [ "..." ], "buildOptions": { "xmlDoc": true }, "frameworks": { "net451": { }, "netstandard1.6": {} }, "dependencies": { "Microsoft.AspNetCore.Mvc": "1.0.0", "Microsoft.AspNetCore.Mvc.Formatters.Json": "1.0.0", "Microsoft.Extensions.Logging.Abstractions": "1.0.0", "Newtonsoft.Json": "9.0.1" } } 

Any ideas?

+7
source share
1 answer

This reason is that "Newtonsoft.Json" has a strong name.

For this you need <dependentAssembly> . This is in older .config methods, done as follows: (in <runtime> )

  <dependentAssembly> <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" /> <bindingRedirect oldVersion="0.0.0.0-9.0.1.0." newVersion="9.0.1.0" /> </dependentAssembly> 
0
source share

All Articles