143
Views
8
Comments
Problem with Invoke method in extension
Question

Hi,

I try to create extension to call Action by it's name from the set with the same input parameter. I found discussion https://www.outsystems.com/forums/discussion/59902/call-actions-from-a-module-from-an-extension/ and tried extension https://www.outsystems.com/forge/component-overview/3283/action-reflection 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 https://docs.microsoft.com/en-us/dotnet/api/system.reflection.methodbase.invoke?view=netframework-1.1 that

Thanks.

mvp_badge
MVP
Rank: #167

Hello Daryna,

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

Champion
Rank: #87

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!

mvp_badge
MVP
Rank: #167

I'm still thinking about this one...

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

Rank: #496

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.

Rank: #25874

Hi Daryna, 

Did you managed to succeed in calling actions with parameters dynamically? I am also trying to accomplish it but have not any luck yet.


Rank: #496

Hi Romano,

Unfortunately, I didn't manage to do it. So the question is still open.

Rank: #733

Hi,

I'm facing the same problem.

Any ideas?


Thank you