locked
Dynamically load a Workflow RRS feed

  • Question

  • Hi

    I want to dynamically load a workflow (xamlx). I load my WF from my DB. I also have my WF dependency assemblies in my DB.

    To dynamically load my WF, I use a VirtualPathProvider.

    My WF uses a variable foo of MyNS.type Foo, defined on assembly MyAssembly. If my VirtualPathProvider assembly references MyAssembly, it works fine. But, of course, I don’t want this.

    If I try to get my WF wsdl in this case, I have the following error:

    Description:
    An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

    Exception Details:
    System.Xaml.XamlObjectWriterException: 'Cannot create unknown type 'Cannot create unknown type '{http://schemas.microsoft.com/netfx/2009/xaml/activities}Variable({clr-namespace:MyNS.Foo;assembly=MyAssembly}Foo)'.'

    Source Error:
    An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below. 

    Stack Trace:
    [XamlObjectWriterException: 'Cannot create unknown type 'Cannot create unknown type 'Cannot create unknown type '{http://schemas.microsoft.com/netfx/2009/xaml/activities}Variable({clr-namespace:MyNS.Foo;assembly=MyAssembly}Foo)'.' Line number '87' and line position '14'.]
       System.Xaml.XamlObjectWriter.WriteStartObject(XamlType xamlType) +1552281
       System.Xaml.XamlServices.Transform(XamlReader xamlReader, XamlWriter xamlWriter, Boolean closeWriter) +178
       System.Xaml.XamlServices.Load(XamlReader xamlReader) +90
        System.ServiceModel.Activities.Activation.WorkflowServiceHostFactory.CreateServiceHost(String constructorString, Uri[] baseAddresses) +430
       System.ServiceModel.HostingManager.CreateService(String normalizedVirtualPath) +1423
       System.ServiceModel.HostingManager.ActivateService(String normalizedVirtualPath) +50
       System.ServiceModel.HostingManager.EnsureServiceAvailable(String normalizedVirtualPath) +1132

    [ServiceActivationException: The service '/ DynamicHost/Foo.xamlx' cannot be activated due to an exception during compilation.  The exception message is: 'Cannot create unknown type 'Cannot create unknown type '{http://schemas.microsoft.com/netfx/2009/xaml/activities}Variable({clr-namespace:MyNS.Foo;assembly=MyAssembly}Foo)'.' Line number '87' and line position '14'..]
       System.Runtime.AsyncResult.End(IAsyncResult result) +900320
       System.ServiceModel.Activation.HostedHttpRequestAsyncResult.End(IAsyncResult result) +189486
       System.Web.AsyncEventExecutionStep.OnAsyncEventCompletion(IAsyncResult ar) +107

    So I use AppDomain.CurrentDomain.AssemblyResolve in order to load dependences assemblies.

    In this case, I can define my variable but I can’t use it!

    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

    Exception Details: System.Activities.InvalidWorkflowException: The following errors were encountered while processing the workflow tree:
    'VisualBasicReference<Foo>': Compiler error(s) encountered processing expression "foo".
    Type 'Foo' is not defined.

    Source Error:
    An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below. 

    Stack Trace:
    [InvalidWorkflowException: The following errors were encountered while processing the workflow tree:
    'VisualBasicReference<Foo>': Compiler error(s) encountered processing expression "foo".
    Type 'Foo' is not defined.]

       System.Activities.WorkflowInspectionServices.CacheMetadata(Activity rootActivity, LocationReferenceEnvironment hostEnvironment) +1849538
       System.ServiceModel.Activities.WorkflowService.WalkActivityTree() +108
       System.ServiceModel.Activities.WorkflowService.GetContractDescriptions() +186
       System.ServiceModel.Activities.WorkflowServiceHost.CreateDescription(IDictionary`2& implementedContracts) +143
       System.ServiceModel.ServiceHostBase.InitializeDescription(UriSchemeKeyedCollection baseAddresses) +174
       System.ServiceModel.Activities.WorkflowServiceHost.InitializeDescription(WorkflowService serviceDefinition, UriSchemeKeyedCollection baseAddresses) +82
       System.ServiceModel.Activities.WorkflowServiceHost.InitializeFromConstructor(WorkflowService serviceDefinition, Uri[] baseAddresses) +206
       System.ServiceModel.Activities.Activation.WorkflowServiceHostFactory.CreateWorkflowServiceHost(WorkflowService service, Uri[] baseAddresses) +43

     [ServiceActivationException: The service '/ DynamicHost/Foo.xamlx' cannot be activated due to an exception during compilation.  The exception message is: The following errors were encountered while processing the workflow tree:
    'VisualBasicReference<Foo>': Compiler error(s) encountered processing expression "foo".
    Type 'Foo' is not defined.]
       System.Runtime.AsyncResult.End(IAsyncResult result) +900320
       System.ServiceModel.Activation.HostedHttpRequestAsyncResult.End(IAsyncResult result) +189486
       System.Web.AsyncEventExecutionStep.OnAsyncEventCompletion(IAsyncResult ar) +107

    If anybody can help me, I would greatly appreciate it.

    Thanks

    Matthieu

    Thursday, July 21, 2011 11:01 AM

All replies

  • Hi, Matthieu

    ->"If my VirtualPathProvider assembly references MyAssembly, it works fine. But, of course, I don’t want this."
    Do you get any problem in using VirtualPathProvider?

    To get physcial path of a file in WF service project, you can also see this:
    http://xhinker.com/post/ASPNETASPNET-and-physical-path.aspx

    Regards
    MSDN Community Support
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    This posting is provided "AS IS" with no warranties, and confers no rights. My Blog: http://xhinker.com
    Microsoft Windows Workflow Foundation 4.0 Cookbook
    Wednesday, July 27, 2011 7:52 AM
  • No

    My assemblies / xamlx are stored in the DB.

    My issue is not on the VirtualPathProvider but on the xamlx execution.

    Wednesday, July 27, 2011 3:17 PM