Home Dashboard Directory Help
Search

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


Status: 

Closed
 as Duplicate Help for as Duplicate


2
0
Sign in
to vote
Type: Bug
ID: 743870
Opened: 5/25/2012 3:33:23 AM
Access Restriction: Public
0
Workaround(s)
view
2
User(s) can reproduce this bug

Description

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

//////////////////////////////////////////////////////////////////////
WorkflowService wfService =
XamlServices.Load(@"C:\Aqrate\WFServiceHostPoC\HostConsole\BasicWFService.xamlx")
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.Remove(typeof(ServiceDebugBehavior));
host.Description.Behaviors.Add(new ServiceDebugBehavior { IncludeExceptionDetailInFaults = true });

host.Faulted += new EventHandler(host_Faulted);

host.Open();
//////////////////////////////////////////////////////////////////////

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>
         </p1:InArgument>
        </SendMessageContent>
     </SendReply>

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.
Details
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 =
                (WorkflowService)XamlServices.Load(@"c:\users\tilovell\desktop\BlogCode\WorkflowService1\WorkflowService1\Service1.xamlx");

            Compile(workflow1);

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

        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 =
                Activator.CreateInstance(results.ResultType,
                    new object[] { workflowService.Body }) as ICompiledExpressionRoot;

            CompiledExpressionInvoker.SetCompiledExpressionRoot(
                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:

http://blogs.msdn.com/b/tilovell/archive/2012/05/25/wf4-5-using-csharpvalue-lt-t-gt-and-csharpreference-lt-t-gt-in-net-4-5-compiling-expressions-and-changes-in-visual-studio-generated-xaml.aspx

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(http://support.microsoft.com)
Sign in to post a workaround.
File Name Submitted By Submitted On File Size  
SqmExtensionsLogs.zip (restricted) 5/25/2012 -
VsInfo.xml (restricted) 5/25/2012 -
ScreenShot1.jpg (restricted) 5/25/2012 -
DxDiagOutput.txt (restricted) 5/25/2012 -
ScreenShot.jpg (restricted) 5/25/2012 -