I noticed yesterday that this error was happening in my local Windows Azure emulator when I debugged my web role. But the deployed project still worked on Azure. Today, my deployed project is failing with this same error. HELP PLEASE!
This code block in my Global.axax.cs file's Application_Start method:
GlobalConfiguration.Configuration.MessageHandlers
.Add(new BasicAuthMessageHandler()
{
PrincipalProvider = new PrincipalProvider()
});
throws this error:
Inheritance security rules violated by type: 'System.Net.Http.Formatting.JsonContractResolver'. Derived types must either match the security accessibility of the base type or be less accessible.
when I start debugging (this is an Azure web role project). But only sometimes (actually it seems to happen every OTHER time I debug) ... and all I have to do to fix it is to stop and re-start the debugger. What is causing the problem?
This had something to do with the Newtonsoft.Json assembly. I deleted it from my project's references, cleaned and rebuilt the project (for good measure), and then re-added it and rebuilt the project again. The error went away.
System.Net.Http.Formatting.JsonContractResolver is derived from Newtonsoft.Json. Another thread (here: http://forums.asp.net/t/1812274.aspx/3/10) addressed this same problem by removing Newtonsoft.Json from the GAC, since it was there and System.Net.Http.Formatting was not. This apparently solved a person's problem, although it seems backward to me (why can't the base type be in the GAC while the derived type is not? Isn't the error saying the problem is the other way around??).
Try updating your nuget packages. I updated mine, and it fixed the issue. I was also having this issue on azure service itself.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With