Workflow Foundation 4.5 “Expression Activity type

2019-06-21 08:48发布

问题:

I am working through the Getting Started Tutorial for WF45 and have run into a problem that looks to have been experience by other people, but not in the same way that I am experiencing it. I am hoping that someone else has a solution for me.

When I work through the Tutorial, all is good till I have to run it from the workflow host. At that point the instantiation of the workflow fail and returns the following message.

"Expression Activity type 'CSharpValue`1' requires compilation in order to run. Please ensure that the workflow has been compiled."

I have tried downloading the source from Windows Workflow Foundation (WF45) - Getting Started Tutorial in case I had missed a step but the error still persists.

Reading online it seems that workflows with embedded C# expressions need to be complied, but as I understand it this happens by default when using VS2012 and the workflow designer? I have tried to implement the CompileExpressions method found here but that did not help. I did read that there was a problem during the pre-release version where C# expressions caused this problem, and yet VB projects worked. Testing this, I see that I am suffering this exact case. The VB tutorial runs fine, but the C# version fails with this exception.

Furthermore and dare I mention it: This is not a problem on my colleague's machine, so I think it is a configuration problem on my machine...

Update & dodge fix:

So, I have managed to fix the problem, although I am not happy with the solution and would love to hear if anyone has a decent reason for this happening.

My fix was to replace my Microsoft.Common.targets file in the \Framework\v4.0.30319 folder with my colleague's version of the same file. This has solved the problem. What else it has broken remains to be seen...

回答1:

The original Problem thread is pretty old, but may be your find that helpfull either.

I had the same Problem with my dynamic activities and found that the documentation is wrong:

This is the code which produces the error above:

string path = @"myActivity.xaml";

            Activity activity = ActivityXamlServices.Load(path);



            IDictionary<string, object> dictionary = new Dictionary<string, object>
            {
                { "Arg", 1},
            };

            IDictionary<string, object> output = WorkflowInvoker.Invoke(activity, dictionary);

and this is the working code:

string path = @"myActivity.xaml";

            ActivityXamlServicesSettings settings = new ActivityXamlServicesSettings
            {
                CompileExpressions = true
            };


            Activity activity = ActivityXamlServices.Load(path, settings);

            IDictionary<string, object> dictionary = new Dictionary<string, object>
            {
                { "ArgNumberToEcho", 2},
            };

            IDictionary<string, object> output = WorkflowInvoker.Invoke(activity, dictionary);


回答2:

This might help someone - what worked for me was I had line breaks in the Expression window for one my of Assigns. Removed the line breaks and it started working.



回答3:

Another cause of this error is when an expression has too many \r\n in the value.

So if you had an Assign activity with something like this for the "Value" section

new myobject(){
     param1=val1,
     param2=val2,   
     param3=val3,
     param4=val4,
     param5=val5,    
     param6=val6,
}

Change it to this:

new myobject(){param1=val1,param2=val2,param3=val3,param4=val4,param5=val5,param6=val6,}

Now hold both thumbs and hope it fixes the error.