Newtonsoft reference breaks web services
I have added a WebService to my website that references NewtonSoft.JSON
library and it is giving me the following error:
'Formatting' is an ambiguous reference between 'Newtonsoft.Json.Formatting' and 'System.Xml.Formatting'
I obviously don't want to change the .NET page belo开发者_如何转开发w, has anybody come across this issue before? Is there any way to disable the reference for WebServices?
As you may already kinow, this happens because Formatting exists in both the namespaces you referred and the compiler is unable to distinguish it.
Why dont you CNTRL+F and Replace all Formatting to Newtonsoft.Json.Formatting or System.Xml.Formatting
Just realised the assembly was referenced directly in the web config pages section, when I removed it it was fixed. As this was mvc 2 it should be no issue...
Thanks
As you said, it's because you have Newtonsoft.Json in your Web.config namespaces element. I actually do really want it there, because I use JsonConvert.SerializeObject in my front end in several places. It uses standard "using" syntax, so rather than find and replace throughout my code, I decided to only import that one class by using the following:
<add namespace="JsonConvert=Newtonsoft.Json.JsonConvert" />
精彩评论