I have an Activity where I declared a InArgument without a type (because I want to know the type of the Expression at design time).
When I execute the activity I get this error in 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;
}
}
Here is what I did:
The workflow runtime needs to know about the used types in arguments, so the cacheMetadata is the key to make it work, CacheMetadata uses reflection to know about arguments, notice that only works 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));
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With