Problem with Invoke method in extension


I try to create extension to call Action by it's name from the set with the same input parameter. I found discussion and tried extension to have a starting point but it didn't work.

I tried to find issue and separated this row

actionsType.InvokeMember(string.Format("Action{0}", ssactionName), 
      BindingFlags.InvokeMethod | BindingFlags.Static | BindingFlags.Public, 
      null, null, new object[] { contextInstance });

into two rows

MethodInfo myMethod = actionsType.GetMethod(string.Format("Action{0}", ssactionName),
      BindingFlags.InvokeMethod | BindingFlags.Static | BindingFlags.Public);
myMethod.Invoke(null, new object[] { contextInstance });

When I put a breakpoint after the first of this two rows, I see my method, so until then everything is correct. But after next step I get the error 

System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.NullReferenceException: Object reference not set to an instance of an object.

But I found in the documentation that


Hello Daryna,

What exactly is your use case? Is it plain experimentation or something else?

João Heleno wrote:

Hello Daryna,

What exactly is your use case? Is it plain experimentation or something else?

 Hi João,

I want to optimize action with switch that will be very big in the future. I have set of actions that are different inside but have similar names and the same input parameters and I want to choose the next action according to the incoming data.


Wow, this can be done? Thank you for asking this question because I would never have found this behavior. It opens door that can solve a major business case for us!

I'm still thinking about this one...

What everyone should realize is that this relies on undocumented Platform features that can suddenly change/disappear.

Yes, it was undocumented OutSystems feature but it looks strange that the result of calling the method in the extension is inconsistent with official .Net documentation now.