When I try to call JsonConvert.DeserialiseObject
via reflection I get an AmbiguousMatchException
despite me specifying the type of the parameter for the overload I want to call
MethodInfo method = typeof(JsonConvert).GetMethod("DeserializeObject", new[] { typeof(string) });
Not sure what other info I can supply so that it finds a unique match
any ideas?
As mentioned, you can use the GetMethods()
method with Linqs Single()
method to find the MethodInfo you are looking for:
var method = typeof (JsonConvert).GetMethods().Single(
m =>
m.Name == "DeserializeObject" &&
m.GetGenericArguments().Length == 1 &&
m.GetParameters().Length == 1 &&
m.GetParameters()[0].ParameterType == typeof(string));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With