Search code examples
c#iisworkflow-foundation-4workflow-foundation

WF4.5 not compiling side-by-side c# workflows


I have an IIS hosted xamlx workflow with c# expressions that I'm trying to run in side-by-side versioning.

I did exactly like this article: Side by side versioning of workflow services

New instances of the workflow works as expected, but when I call an instance of a prior version of the workflow, it raises an error telling me that it's not compiled.

Error:

Unable to locate the ICompiledExpressionRoot for compiled location 'auxData'. Make sure that the definition for the activity containing this expression has been compiled.

BTW, I have a custom factory that compiles the workflow.

<serviceActivations>        
    <add service="Service1.xamlx" relativeAddress="~/Service1.xamlx" factory="MyServiceHostFactory" />
</serviceActivations>

Solution

  • After analyzing the source code from .Net, I realized that the method CreateWorkflowServiceHost that I override in my custom workflow factory, adds all supported versions in it's return object.

    All I had to do is iterate this collection and compile them all.

    Final source code:

        protected override WorkflowServiceHost CreateWorkflowServiceHost(WorkflowService service, Uri[] baseAddresses)
        {
            var host = base.CreateWorkflowServiceHost(service, baseAddresses);
    
            // add your customizations here…
            CompileExpressions(service.Body);
            foreach (var supportedVersion in host.SupportedVersions)
            {
                CompileExpressions(supportedVersion.Body);
            }
    
            return host;
        }