Loading file with ActivityXamlServices.Load does not resolve references activities RRS feed

  • Question

  • Hi,

    I followed these steps in order to spike a pure Xaml workflow with activity dependencies load:

    Create a a workflow console project
    Create an activity called Workflow1 .
    Create an activity called Activity1 in the same project.
    Drag Activity1 on to Workflow1 in the designer.

    I then change the code in Program.cs to load the workflow directly from the file:

          Activity workflow = ActivityXamlServices.Load("../../Workflow1.xaml"

    I then get the following error:

    Cannot create unknown type '{clr-namespace:WorkflowConsoleApplication2}Activity1'.

    I then proceed with the following steps:

    Add a new activity library project to the solution, create an activity called Activity2 in it.
    Remove Activity1 from the designer in Workflow1.
    Add Activity2 on to the designer for Workflow1 from the toolbox.

    Run the console, and BAM! it works...

    So it seems that it does not resolve the types correcly if the activity lives in the same project and the workflow gets loaded with ActivityXamlServices from a file.

    Before I found the solution, I also tried loading it with a sample from BETA 1 (from this thread http://social.msdn.microsoft.com/Forums/en-US/wfprerelease/thread/615ce747-3ff1-4a06-9681-687ae2918f84 ):

          IList<Assembly> assem = new List<Assembly>();
          XamlSchemaContext context = new XamlSchemaContext(assem);
          using(XmlReader xmlReader = XmlReader.Create("../../Workflow1.xaml"))
            using(XamlReader xamlReader = new XamlXmlReader(xmlReader, context))
              var workflow = ActivityXamlServices.Load(xamlReader);
              WorkflowInvoker.Invoke(workflow, parameters);

    I also couldn't get that to work...

    I assume this is a bug?

    Hendrik (http://hendrikswan.wordpress.com )
    • Edited by hendrik swanepoel Friday, January 8, 2010 8:46 AM Had to fix code formatting after first edit - weird
    Friday, January 8, 2010 8:39 AM


  • Hi Hendrik,

    This is actually By Design.  Basically, loading the xaml within the same assembly via ActivityXamlServices requires explicitly setting the LocalAssembly.  The following code would work for you on the Beta2 build.  As you've found, referencing the xaml from a different project (assembly) would not have this issue.

    Activity workflow = ActivityXamlServices.Load(ActivityXamlServices.CreateReader(new XamlXmlReader(@"../../Workflow1.xaml", new XamlXmlReaderSettings { LocalAssembly = System.Reflection.Assembly.GetExecutingAssembly() })));


    For detailed explanation, please refer to Max Wilson's post at http://social.msdn.microsoft.com/Forums/en/wfprerelease/thread/0086f55d-3ed1-4015-90ca-ad8144178255


    This posting is provided "AS IS" and confers no rights or warranties.

    Sunday, January 10, 2010 5:32 PM