GetParameters for Open Generic methods is not supported. Using CF 3.5

Nov 27, 2009 at 9:27 AM

 

Hi~

 

First of all, I am a newbie for Json.net. 

Nowadays I have tested some code based on .NET CF 3.5 (Windows Mobile 6.5) to use Json.net

Actually before I tested my code on .NET CF 3.5, I've tested .NET 3.5 on my desktop first.

There was no problem on .NET 3.5.  It worked fine.

But when I applied my code on .NET CF 3.5, I found the problem like "GetParameters for Open Generic methods is not supported." 

Here is my object for Json.net

   // My object class
   public class OutputResult
   {
      public string ResultCode { get; set; }
      public string ResultString { get; set; }
      public List<string> Features { get; set; }
   }

   ...
   
   // Set Object class
   outputResult.ResultString = value;
                     
   // Set List
   List<string> f = new List<string>();
   f.Add("hello");

   // append List
   outputResult.Features = f;

   ...

   // Using Json.net
   string result = JsonConvert.SerializeObject(outputResult);  // Got GetParameters for Open Generic methods...

When I removed List attribute from my Object, the serializing was working good.
But I added List attribute(ie, Features), I got an exception.
What was problem in my codes?

Thank for any suggestions.
Coordinator
Nov 30, 2009 at 6:27 AM

Hmm I don't get that error in my unit tests but I think that is because the unit tests aren't running on the compact framework CLR.

I've made a change in the code which I think will fix your issue. It is checked into CodePlex if you want to build from it.

Nov 30, 2009 at 11:38 PM

First, thanks for your quick reply.

I traced that exception using Visual Studio and I found the code which raised the error.  

                // DefaultContactResolver.cs 

 

        Type prevAttributeType = null;
        ParameterInfo[] parameters = method.GetParameters();  // raised the error in the foreach loop

And I just tried ignoring the exception using try phrase. Then it worked O.K.
Thanks a lot again.

 

Coordinator
Dec 2, 2009 at 12:21 AM

Ok, that is where I thought it was too. I've used a different fix and I haven't been able to test that it works. If you have time try removing the try/catch and replacing it with this code at the start of the foreach:

        if (method.ContainsGenericParameters)
continue;

That will skip any methods which will cause that problem.

~ James

Dec 2, 2009 at 2:32 AM

Hi~ As you guided, I removed the try/catch code and put your code.  It worked good with no exception.

Thanks a lot.