Inheritance security rules violation on Windows 8 (.NET 4.5)

Feb 11, 2013 at 6:54 PM
Edited Feb 11, 2013 at 6:54 PM
I get the following exception once I initialize a new instance of JsonMediaTypeFormatter class in .NET 4.5 (but only on Windows 8):

System.TypeLoadException: 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.

Any idea, how to solve this problem?

Thanks in advance,

Jürgen
Jul 6, 2013 at 4:59 AM
Same problem here.

It happens when I import a PCL using Newtonsoft.Json Portable in my web.api project.

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.

at System.Net.Http.Formatting.JsonMediaTypeFormatter..ctor()
at System.Net.Http.Formatting.MediaTypeFormatterCollection.CreateDefaultFormatters()
at System.Net.Http.Formatting.MediaTypeFormatterCollection..ctor()
at System.Web.Http.HttpConfiguration.DefaultFormatters()
at System.Web.Http.HttpConfiguration..ctor(HttpRouteCollection routes)
at System.Web.Http.GlobalConfiguration.<.cctor>b__0()
at System.Lazy1.CreateValue()
at System.Lazy
1.LazyInitValue()
at System.Web.Http.GlobalConfiguration.get_Configuration()
at CacaPalavras.Web.App_Start.NinjectWebCommon.Start() in c:\Projects\Web\App_Start\NinjectWebCommon.cs:line 28
Jul 23, 2013 at 12:15 PM
Edited Jul 23, 2013 at 12:24 PM
I have the same problem (running Windows 8).

I use a HttpSelfHostConfiguration and reference a PCL project which itself references the PCL library of Newtonsoft.Json.

My solution was setting CopyLocal to False (PCL reference of Newtonsoft.Json in my PCL library) so that the Host uses the .NET 4.5 DLL of Newtonsoft.Json

Or would it be better to use the PCL library of Newtonsoft.Json everywhere instead of the .NET 4.5 assembly?