Generic InArgument throws an exception trying to get a value

I have an Activity where I declared InArgument without a type (because I want to know the type of expression at design time).

When I execute the action, I get this error in the var contentTelegram line:

"The argument of type '<type>' cannot be used. Make sure that it is declared on an activity." 

Here is my code:

 public InArgument Content { get; set; } protected override PlcMessage Execute(CodeActivityContext context) { try { var contentTelegram = Content.Get(context); return new PlcMessage(); } catch (Exception ex) { throw; } } 
+4
source share
1 answer

Here is what I did:

The workflow script needs to know about the types used in the arguments, so cacheMetadata is the key to make it work, CacheMetadata uses reflection to know about the arguments, notices that it works only for simple cases.

 public sealed class MyActivity: CodeActivity { private RuntimeArgument outMyRuntimeArgument; // Define an activity input argument of type string public OutArgument MyUntypedArgument { get; set; } protected override void CacheMetadata(CodeActivityMetadata metadata) { outMyArgument= new RuntimeArgument("MyUntypedArgument", MyUntypedArgument.ArgumentType, ArgumentDirection.Out); metadata.Bind(MyUntypedArgument, outArgument); metadata.AddArgument(outMyArgument); } protected override void Execute(CodeActivityContext context) { context.SetValue(outMyRuntimeArgument, Activator.CreateInstance(Type)); } } 
+3
source

All Articles