The following code fails when I invoke the method. No exceptions; everything just crashes. This code is in a Windows Phone 7 Portable Class Library, any idea what’s going on?
public static object Deserialize(string input, Type type)
{
var castMethod = typeof(ModelBase).GetMethod("Cast").MakeGenericMethod(type);
object castedObject = castMethod.Invoke(null, new object[] { input });
return castedObject;
}
public static T Cast<T>(string input)
{
return JsonConvert.DeserializeObject<T>(input);
}
MakeGenericMethod is present but not supported in Silverlight for Windows Phone.
Check here under “platform notes”: http://msdn.microsoft.com/en-us/library/system.reflection.methodinfo.makegenericmethod(v=vs.95).aspx