NotSupportedException

Dec 14, 2009 at 1:04 PM

GetParameters for Open Generic methods is not supported.

Stack Trace:

at System.Reflection.RuntimeMethodInfo.GetParameters()
   at Newtonsoft.Json.Serialization.DefaultContractResolver.InitializeContract(JsonContract contract)
   at Newtonsoft.Json.Serialization.DefaultContractResolver.CreateArrayContract(Type objectType)
   at Newtonsoft.Json.Serialization.DefaultContractResolver.CreateContract(Type objectType)
   at Newtonsoft.Json.Utilities.ThreadSafeStore`2.AddValue(Type key)
   at Newtonsoft.Json.Utilities.ThreadSafeStore`2.Get(Type key)
   at Newtonsoft.Json.Serialization.DefaultContractResolver.ResolveContract(Type type)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.ShouldWriteReference(Object value, JsonProperty property)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.WriteMemberInfoProperty(JsonWriter writer, Object value, JsonProperty property)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeObject(JsonWriter writer, Object value, JsonObjectContract contract)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeValue(JsonWriter writer, Object value, JsonConverter memberConverter)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.Serialize(JsonWriter jsonWriter, Object value)
   at Newtonsoft.Json.JsonSerializer.SerializeInternal(JsonWriter jsonWriter, Object value)
   at Newtonsoft.Json.JsonSerializer.Serialize(JsonWriter jsonWriter, Object value)
   at Newtonsoft.Json.JsonConvert.SerializeObject(Object value, Formatting formatting, JsonSerializerSettings settings)
   at Newtonsoft.Json.JsonConvert.SerializeObject(Object value)
   at Wizcom.InOrderII.Sockets.Mobile.Serialize.SerializeToString[T](Order data)........

 

Why could this come up for no reason while everything seems to be fine, this only comes when using the CF serializer. Tested something similar for the Desktop

and seems to work. What is this error tells me?

My serializing method:

        public static string SerializeToString<T>(T data) where T : class
        {
            return JsonConvert.SerializeObject(data);
        }

My class i want to serialize:

    public class Order
    {
        public int Id { set; get; }
        public DateTime OrderDate { set; get; }
        public int StationId { set; get; }
        public string OrderIdentifier { set; get; }
        public List<OrderLine> OrderLines = new List<OrderLine>();
   }
Any thoughts?

Coordinator
Dec 14, 2009 at 8:09 PM

Get the latest version of the source code from CodePlex and build and use that. This bug has been fixed.

Dec 15, 2009 at 9:34 AM

No it is not fixed.

 

Coordinator
Dec 15, 2009 at 10:01 PM
Edited Dec 15, 2009 at 10:02 PM

Hmmm I'm not sure then. The exact same problem was fixed here - http://json.codeplex.com/Thread/View.aspx?ThreadId=76384

Dec 16, 2009 at 8:42 AM

I Added 

 if (method.ContainsGenericParameters)
continue;

In DefaultContactResolver.cs at line 183 and build. This worked.

 

Coordinator
Dec 16, 2009 at 8:57 AM

Ah ok. I meant get the latest source code from the Source Code tab on CodePlex. It has that new check.

Dec 16, 2009 at 11:25 AM

I downloaded the json-43557.zip. Looks OK