Search code examples
c#workflow-foundation-4

Passing control as in argument WF4


Im trying to pass a complex object, a ScriptControl, as an In argument for workflow. The error I get is:

`The following errors were encountered while processing the workflow tree:
'Literal<ScriptControl>': Literal only supports value types and the immutable type     System.String.  The type ScriptDisplay.ScriptControlcannot be used as a literal.`

I am newer to workflow and I understand the problem, but how do I fix it?


Solution

  • Without seeing your code I can't be certain but this is usually caused by using WorkflowInvoker. e.g.

    WorkflowInvoker.Invoke(workflow,ScriptControl)
    

    The way round this is to put the complex object into a dictionary.

    ScriptControl scriptControl= new ScriptControl{ initialise your object here };
    
    Dictionary<string, object> inputDictionary = new Dictionary<string, object> { { "ScriptControl", scriptControl } };
    
    var output = WorkflowInvoker.Invoke(workflow, inputDictionary );
    

    You then use the dictionary as usual to access the scriptControl object.

    e.g.

    var x = dictionary["ScriptControl"].some property of your ScriptControl object
    

    Ron Jacobs talks more about this here