chevron-thin-right chevron-thin-left brand cancel-circle search youtube-icon google-plus-icon linkedin-icon facebook-icon twitter-icon toolbox download check linkedin phone twitter-old google-plus facebook profile-male chat calendar profile-male
0 votes

I'm using Isolate.Invoke.Method to call a protected virtual method, which has no overloads, and I'm getting a NullReferenceException.

Here is the StackTrace:

   at ay.a(Object A_0)
   at System.Linq.Enumerable.WhereSelectArrayIterator`2.MoveNext()
   at System.Linq.Buffer`1..ctor(IEnumerable`1 source)
   at System.Linq.Enumerable.ToArray[TSource](IEnumerable`1 source)
   at ay.a(String A_0, IEnumerable`1 A_1, Type A_2, Boolean A_3)
   at ay.a(Object A_0, String A_1, Object[] A_2)
   at Technical.Web.CascadeResXResourceProviderTest.CreateApplicationResourceManager_AppKeyNull()

One of parameters is a null value and this is the main problem.

As far as I can see the Isolate.Invoke.Method method is inferring parameter types from parameter objects (parameter.GetType()). Using this approach null parameter values are not supported and throw the NullReferenceException.

I can, naturally, get the protected method MethodInfo and do the method invoke, so, this is not a severe problem.

To solve the problem I propose either:

  • 1. check for null object parameters and throw a specific exception. Also change the documentation according to this behavior.
    2. extend the Isolate.Invoke.Method so that, when no overload exists, bypass the type inference and simply use the existing MethodInfo. If method signature don't match the parameters array the usual exception will be throw.
    3. create an Isolate.Invoke.Method overload with a signature that includes the Type[] that should be used to get the correct MethodInfo.

Suggestion 3 is only to avoid doing similar task in different ways:
using Isolate.Invoke.Method for invoking without null arguments
using MethodInfo.Invoke the same method but with null arguments

asked by nmgomes (680 points)

2 Answers

0 votes
I've been thinking about this for a few tools I'm thinking of building and I came up with the concept of typed nulls (Null.Of<T>() and Null.Of(Type)).
These typed nulls are used for overload resolution and then passed null as the value for the invocation argument.
Still a work in progress...
answered by paulo.morgado (11k points)
0 votes
Hi Nuno,

I checked it out and you are right it is a bug :twisted: Thanks for letting us know.
I'll bring your suggestion to the team.

Paulo: Cool 8) let us know when it's out.
answered by ohad (35.5k points)