Workflow Foundation 4.5 - WorkflowServiceHost - XAMLX - Expression Activity type 'CSharpValue`1' requires compilation in order to run. - by CIGNUM

Status : 

  Duplicate<br /><br />
		This item appears to be a duplicate of another existing Connect or internal item.<br /><br />
		A more detailed explanation for the resolution of this particular item may have been provided in the comments section.

Sign in
to vote
ID 743870 Comments
Status Closed Workarounds
Type Bug Repros 2
Opened 5/25/2012 3:33:23 AM
Access Restriction Public


I use WorkflowServiceHost inside a C# console application to load a XAMLX workflow designed in VisualStudio 2011.

WorkflowService wfService =
 as WorkflowService;

Uri address = new Uri("http://localhost:1234/WorkflowService");
WorkflowServiceHost host = new WorkflowServiceHost(wfService, address);
// Behaviours
host.Description.Behaviors.Add(new ServiceMetadataBehavior { HttpGetEnabled = true });
host.Description.Behaviors.Add(new ServiceDebugBehavior { IncludeExceptionDetailInFaults = true });

host.Faulted += new EventHandler(host_Faulted);


This workflow contains a Receive and a SendReplyToRecieve shapes (see ScreenShot1.jpg file).

I also added the workflow a string variable and used it in the SendReplyToRecieve Content field in order to return a string value to the caller (see ScreenShot1.jpg file).

I use the VS2011 WcfTestClient to call the service and execute the workflow (see ScreenShot.jpg file).

I get the following error in the WcfTestClient consolle, instead of receiving the response message from the workflow execution (see ScreenShot.jpg file):

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

As far as I am concernet this refers to the XAMLX section:

<SendReply Request="{x:Reference __ReferenceID0}" DisplayName="SendReplyToReceive" sap2010:WorkflowViewState.IdRef="SendReply_2">
        <SendMessageContent DeclaredMessageType="x:String">
          <p1:InArgument x:TypeArguments="x:String">
            <mca:CSharpValue x:TypeArguments="x:String">extensionResultVariable</mca:CSharpValue>

If I remove the use of the variable in the SendReplyToRecieve shape, everithing works just fine.

If I actually design the same exactly workflow as an activity and then I load it on the WorkflowServiceHost  to run in the same manner as above, the problem does not occur and I can use the variable in the SendReplyToRecieve shape receiving its value in the WcfTestClient without problems.
Sign in to post a comment.
Posted by Srinivasan R on 12/17/2012 at 3:05 PM
This is still an issue with VS2012 also. Is there a way to tap into the request and apply the compile using global.asax or something?
Posted by Microsoft on 6/8/2012 at 9:35 AM
Hello Cinnio and thank you for your feedback, I believe this is exactly the same issue as another connect bug related to C# expressions in WorkflowServiceHost, and so you will see this issue resolved as duplicate. However, let me explain here that in .Net 4.5 the current design is that you will need to precompile the C# expressions prior to creating the WorkflowServiceHost. We will be adding further documentation for this scenario and/or making this scenario simpler.

In the meantime, I think the below expression Compilation code provides a solution to the problem.

static void Main(string[] args)
            // Create and cache the workflow definition
            WorkflowService workflow1 =


            var host = new WorkflowServiceHost(workflow1, new Uri("http://localhost:8293/Service1.xamlx"));
            Console.WriteLine("Press enter to quit");

        static void Compile(WorkflowService workflowService)
            TextExpressionCompilerSettings settings = new TextExpressionCompilerSettings
                Activity = workflowService.Body,
                Language = "C#",
                ActivityName = workflowService.Name + "_CompiledExpressionRoot",
                ActivityNamespace = string.Join(".", "CompiledExpressions"),
                RootNamespace = null,
                GenerateAsPartialClass = false,
                ForImplementation = false, // Important tip - ForImplementation should only be true when compiling an ActivityBuilder, it must be false when compiling an Activity such as a WorfkflowService body.

            TextExpressionCompilerResults results =
                new TextExpressionCompiler(settings).Compile();

            if (results.HasErrors)
                throw new Exception("Compilation failed.");

            ICompiledExpressionRoot compiledExpressionRoot =
                    new object[] { workflowService.Body }) as ICompiledExpressionRoot;

                workflowService.Body, compiledExpressionRoot);

For some further details of C# expressions in .Net 4.5 and expression compilation, you can also, in the interim, refer to this blog post:

Thank you for your patience, and please do reply as soon as possible if this does not address your problem.
Posted by Microsoft on 5/27/2012 at 7:46 PM
Thanks for your feedback.

We are rerouting this issue to the appropriate group within the Visual Studio Product Team for triage and resolution. These specialized experts will follow-up with your issue.
Posted by MS-Moderator01 on 5/25/2012 at 3:43 AM
Thank you for your feedback, we are currently reviewing the issue you have submitted. If this issue is urgent, please contact support directly(