1

Closed

System.Security.VerificationException (Operation could destabilize the runtime.)

description

SerializeObject produces an exception.
.NET: 4.0
Json.NET: Json40r2
 
Code:
 
var feed = Newtonsoft.Json.JsonConvert.SerializeObject(new Feed());
 
 
Exception:
 
System.Security.VerificationException was caught
Message=Operation could destabilize the runtime.
Source=Newtonsoft.Json
StackTrace:
   at Newtonsoft.Json.Serialization.DefaultContractResolver.CreateMemberValueProvider(MemberInfo member) in d:\Development\Releases\Json\Working\Src\Newtonsoft.Json\Serialization\DefaultContractResolver.cs:line 655
   at Newtonsoft.Json.Serialization.DefaultContractResolver.CreateProperty(MemberInfo member, MemberSerialization memberSerialization) in d:\Development\Releases\Json\Working\Src\Newtonsoft.Json\Serialization\DefaultContractResolver.cs:line 668
   at Newtonsoft.Json.Serialization.DefaultContractResolver.CreateProperties(Type type, MemberSerialization memberSerialization) in d:\Development\Releases\Json\Working\Src\Newtonsoft.Json\Serialization\DefaultContractResolver.cs:line 634
   at Newtonsoft.Json.Serialization.DefaultContractResolver.CreateObjectContract(Type objectType) in d:\Development\Releases\Json\Working\Src\Newtonsoft.Json\Serialization\DefaultContractResolver.cs:line 282
   at Newtonsoft.Json.Serialization.DefaultContractResolver.CreateContract(Type objectType) in d:\Development\Releases\Json\Working\Src\Newtonsoft.Json\Serialization\DefaultContractResolver.cs:line 545
   at Newtonsoft.Json.Serialization.DefaultContractResolver.ResolveContract(Type type) in d:\Development\Releases\Json\Working\Src\Newtonsoft.Json\Serialization\DefaultContractResolver.cs:line 188
   at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.GetContractSafe(Object value) in d:\Development\Releases\Json\Working\Src\Newtonsoft.Json\Serialization\JsonSerializerInternalWriter.cs:line 86
   at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.Serialize(JsonWriter jsonWriter, Object value) in d:\Development\Releases\Json\Working\Src\Newtonsoft.Json\Serialization\JsonSerializerInternalWriter.cs:line 70
   at Newtonsoft.Json.JsonSerializer.SerializeInternal(JsonWriter jsonWriter, Object value) in d:\Development\Releases\Json\Working\Src\Newtonsoft.Json\JsonSerializer.cs:line 451
   at Newtonsoft.Json.JsonSerializer.Serialize(JsonWriter jsonWriter, Object value) in d:\Development\Releases\Json\Working\Src\Newtonsoft.Json\JsonSerializer.cs:line 443
   at Newtonsoft.Json.JsonConvert.SerializeObject(Object value, Formatting formatting, JsonSerializerSettings settings) in d:\Development\Releases\Json\Working\Src\Newtonsoft.Json\JsonConvert.cs:line 591
   at Newtonsoft.Json.JsonConvert.SerializeObject(Object value) in d:\Development\Releases\Json\Working\Src\Newtonsoft.Json\JsonConvert.cs:line 528
   at My.App.Program.Main() in C:\My\My.App\Program.cs:line 53
InnerException:
Closed May 5, 2011 at 11:27 AM by JamesNK

comments

uyelikhesabi wrote May 3, 2011 at 6:36 AM

Resolved by updating the references to the Json library inside all of the projects in the solution.

blake05 wrote Jun 17, 2011 at 10:45 PM

I'm getting this error in my existing projects (latest nightly build):

System.Security.VerificationException was unhandled by user code
Message=Operation could destabilize the runtime.
Source=Newtonsoft.Json
StackTrace:
   at Newtonsoft.Json.Serialization.DefaultContractResolver.CreateMemberValueProvider(MemberInfo member)
   at Newtonsoft.Json.Serialization.DefaultContractResolver.CreateProperty(MemberInfo member, MemberSerialization memberSerialization)
   at Newtonsoft.Json.Serialization.DefaultContractResolver.CreateProperties(Type type, MemberSerialization memberSerialization)
   at Newtonsoft.Json.Serialization.DefaultContractResolver.CreateObjectContract(Type objectType)
   at Newtonsoft.Json.Serialization.DefaultContractResolver.CreateContract(Type objectType)
   at Newtonsoft.Json.Serialization.DefaultContractResolver.ResolveContract(Type type)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.GetContractSafe(Type type)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.ReadForType(JsonReader reader, Type t, JsonConverter propertyConverter)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize(JsonReader reader, Type objectType)
   at Newtonsoft.Json.JsonSerializer.DeserializeInternal(JsonReader reader, Type objectType)
   at Newtonsoft.Json.JsonSerializer.Deserialize(JsonReader reader, Type objectType)
   at Newtonsoft.Json.JsonSerializer.Deserialize[T](JsonReader reader)

Versive wrote Aug 11, 2011 at 8:32 PM

Me too.

Here are the offending code fragments :)...

Dictionary<string, string> dargs = new Dictionary<string, string>();
        dargs.Add("typeSourceID", Guid.NewGuid().ToString());
        dargs.Add("typeSourceID2", Guid.NewGuid().ToString());

        Command testCommand = new Command("command", dargs);
The testCommand is the instance that's passed to serialize. Get the same result if I try and pass in a dynamic type.

?
Thanks,
Dave G