I'm working in a WF 4.0 project. This is a part of my own custom activity:
public Activity Create(DependencyObject target)
{
var sequenceModelItem = (target as WorkflowViewElement).ModelItem;
sequenceModelItem
.Properties["Variables"]
.Collection
.Add(new Variable<List<string>>("Provider", provider));
sequenceModelItem
.Properties["Variables"]
.Collection
.Add(new Variable<string>("ProviderSearch"));
return new Sequence
{
Activities =
{
// Some activities...
}
};
}
So Here is the question. In provider I have a list< string > of some providers that i have in my DB. in SequenceModelItem I create a variable with the same type and i associate the list provider to there. Everything is correct, but when I deploy the workflow and Execute, the following error appeare:
*The following errors were encountered while processing the workflow tree: 'Literal<List <String>> ': Literal only supports value types and the immutable type System.String. The type System.Collections.Generic.List`1[System.String] cannot be used as a literal *
For sure that the error is here:
.Add(new Variable<List<string>>("Provider", provider));
But I don't know what I have to do to solve it,
Thanks!!
Could it be that you need to change that line to:
.Add(new Variable<Dictionary<string, object>>( { "Provider", provider }));
Based on this article by Ron Jacobs, it appears that the new Variable is trying to convert your List to a Literal which would fail for references types (List). The articles points that if you want to use a reference type you must use a Dictionary.