C# trouble with including json.net - c#

I have a webpart for SharePoint 2010 written on ASP.Net and I need to use JSON.Net. So I Nugeted Json.NET version 4.5.9. Then problem happens:
Could not load file or assembly 'Newtonsoft.Json, Version=4.5.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' or one of its dependencies. Couldn't locate file.
What should I do?

I had same kind of problem once.
Don't use earlier references.
If you have any, remove them and add Json.Net once again using Nuget.
Install-Package Newtonsoft.Json
It solved for me.

Related

Could not load file or assembly 'Newtonsoft.Json, Version=10.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' in Azure Functions

I am refering a C# library project from my Azure Function (Service bus queue trigger). The library is referencing the Newtonsoft nuget version 10.0.1.
While running the function locally on my visual studio, it gives this error .
{"Could not load file or assembly 'Newtonsoft.Json, Version=10.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' or one of its dependencies. The system cannot find the file specified.":"Newtonsoft.Json, Version=10.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed"}
I tried downgrading to version 10.0.0, but the issue is there.
I stumbled upon this issue link : https://github.com/Azure/azure-functions-vs-build-sdk/issues/107.
And tried downgrading to 9.0.1. But even then the error still occurs.
Note: The library project reference several other library projects which are also referencing Newtonsoft. I am keeping the same version of the nuget all the sub projects.
How to solve this issue?
Pointing all the Newtonsoft dlls in all the sub libraries to version to 9.0.1 solved the issue.

Dual References to IXMLSerializable

I have a class that implements IXMLSerializable in a .NET Standard Library, but I can't compile the library because it's referencing IXMLSerializable in two places. The output is as follows:
error CS0433: The type 'IXmlSerializable' exists in both
'System.Xml.ReaderWriter, Version=4.1.0.0, Culture=neutral,
PublicKeyToken=b03f5f7f11d50a3a' and 'System.Xml.XmlSerializer,
Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'
I only see one reference under the dependencies though (System.Xml.XmlSerializer), which I need for the XML attributes. This is my first crack at a .Net Standard Library, so is there something I'm missing here?
Try upgrading your reference to System.Xml.XmlSerializer to version 4.1.0.0.
The error message says that you have two references to the library, but are using different versions. System.Xml.ReaderWriter is using a newer version than your project is, so you need to get that version.
You could also try removing your reference to System.Xml.XmlSerializer or switching it to an older version.

How to solve the Newtonsoft.Json confilict in vs2015

I try to build the Akka.NET as build all ,but there is a error:
CS0433: Configuration\Hocon\HoconObject.cs(47,10): The type 'JsonIgnoreAttribute' exists in both 'Newtonsoft.Json, Version=4.5.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' and 'Newtonsoft.Json, Version=7.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed'
I don't know why the vs2015 will to find the 'Newtonsoft.Json' in foler C:\Program Files (x86)\Microsoft Visual Studio 12.0\Blend\ not the reference path ..\..\packages\Newtonsoft.Json.7.0.1\lib\net45\Newtonsoft.Json.dll.
Here is the akka.net project file Akka.csproj.
Please help me to solve the problem.Thanks
--------------------Update---------------
I found the Newtonsoft.Json.7.0.1\lib\net45\Newtonsoft.Json.dll as follow:
Is there a problem in Nuget now?
I got similar kind of error once and Solved this by renaming the Dll and adding it to reference.
The other way around is you copy the DLL version to the bin of the project and then add it to reference.
Each time you are building as you referred, visual studio is downloading the latest package and hence this conflict arises.
I would suggest you to go for the second approach.
Thanks,
Anil
I had the same issue, what fixed it for me:
Delete bin and obj folders,
Uninstall-Package Akka, then
Install-Package Newtonsoft.Json to latest version (8.0+)
Then, Install-Package Akka,
which will pick up the latest version of Newtonsoft.Json and be happy :).

Servicestack expecting lower assembly version

If I try to use the JsonServiceClient of Servicestack I always get the following Exception:
Could not load file or assembly 'ServiceStack.Text, Version=4.0.14.0,
Culture=neutral, PublicKeyToken=null' or one of its dependencies.
System cannot find the file specified.":"ServiceStack.Text,
Version=4.0.14.0, Culture=neutral, PublicKeyToken=null
The project runs with .net 4.5 and the Servicestack Version 4.0.15.0. That ist the weirdest thing, because I never had 4.0.14.0 as a reference. I only have a reference to Servicestack.Text 4.0.15.0 and all the other ServiceStack libs in 4.0.15.0
Before I had the same Problem with 3.9.66.0 expecting 3.9.63. But I upgraded via NuGet hoping to solve the Problem but it didn't work.
I just noticed in my Outputfolder that Servicestack.Text was missing. Now I use a direct call to a class in Servicestack.Text and the compiler isn't optimising Servicestack.Text out.

Could not load file Newtonsoft Json

I am developing a Ribbon control and I want to use JSON.NET. I'm having this error :
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.
I've tried a couple of things, that I found here in stackoverflow such as:
reinstall JSON.NET, with nuget console;
Open up packages.config
Delete the Newtonsoft.Json entry.
Save and Build Re-add Newtonsoft.Json from NuGet.
Build and run
checked files on bin folder
nothing seems to work, any ideias?
Do any of the other projects in the same solution also reference Json.Net?
It may be that different projects in the same solution refer to different version of Json.Net.
Finally I found my solution:
Right-click on the "references" of your project.
Add a referencec
In the framework tab, type "json.net". I had two versions: 4.5 and 6.0. I only checked 4.5 and left the 6.0 unchecked.
Rebuild and relaunch the project, and this error disappeared for me.

Categories

Resources