System.MissingMethodException : Method 'blah' not found.
I don't use reflection much in .Net but we are updating some libraries and one C# library was using Microsoft.VisualBasic to call a method!
I replaced it with some basic InvokeMember code but despite the parameters looking correct, I got the above error even though I knew the Property I was calling was present on the target object (.Net sees Properties as methods!)
The problem I had was with the array of objects that are passed to set the property. Generally, the downcast to the correct type would just work when invoking the method but I had changed this:
(FeatureStatus?) val ? 1 : 0
to this:
(object)val ? 1 : 0
Of course, 1 and 0 are integers, not FeatureStatus enum types so when reflection was looking for a property that took a FeatureStatus, it couldn't find one and I got the error. I had to change it to this:
(object)(FeatureStatus?)val ? 1 : 0
So it all boxed up correctly and worked!
I replaced it with some basic InvokeMember code but despite the parameters looking correct, I got the above error even though I knew the Property I was calling was present on the target object (.Net sees Properties as methods!)
The problem I had was with the array of objects that are passed to set the property. Generally, the downcast to the correct type would just work when invoking the method but I had changed this:
(FeatureStatus?) val ? 1 : 0
to this:
(object)val ? 1 : 0
Of course, 1 and 0 are integers, not FeatureStatus enum types so when reflection was looking for a property that took a FeatureStatus, it couldn't find one and I got the error. I had to change it to this:
(object)(FeatureStatus?)val ? 1 : 0
So it all boxed up correctly and worked!