none
"Cannot create unknown type" error when invoking a dynamic activity RRS feed

  • Question

  • I am trying to use WF 4 to create business rule policy activities that I can store as XAML files and execute dynamically so the rules can be changed without recompiling.  I have created an ExecuteActivityFromXAML activity that takes the path to the XAML file and a dictionary of inputs and loads a dynamic activity from the XAML and then uses workflow invoker to invoke the activity passing in the input parameter dictionary.  In another assembly, I have created rule executor activites that wrap each of the xaml rule activities and build the input parameter dictionary and specify the XAML file path.  For example, I have a parent-child object with three rule activities stored as xaml files on disk (they are in my project with a build action of "None") -  ValidateParent, ValidateChildren, and ValidateChild.  I then have 3 activities compiled into my assembly that build the input parameter collection and use the common ExecuteActivityFromXAML activity to invoke the 3 XAML files - ExecuteValidateParent, ExecuteValidateChildren, ExecuteValidateChild.  The ValidateChildren activity is supposed to validate rules on the collection and then loop through each child object and call ValidateChild.  I can call ExecuteValidateParent with no error if it does not reference the other activities, but when I try callt he ExecuteValidateChildren dynamic activity, I get an error that it "Cannot create unknown type" when it executes the common ExecuteActivityFromXAML activity and it lists the ExecuteValidateChild namespace and class.  If the child activity lives in a different assembly I seem to be able to invoke it without any errors but if it is in the same assembly I get this error.  I tried adding an event handler to the current app domains AssemblyResolve event but my event handler never gets hit.  Why is it able to resolve activities in other assemblies but not activities in the same assembly?
    Monday, October 25, 2010 1:54 PM

Answers

  • Hi Heather,

    From the description and error message you provided, I think this is because of the XAML local-assembly namespace conventions, and is the same basic issue as here

    http://stackoverflow.com/questions/2330762/wf4-rc-cannot-create-unknown-type-when-loading-wf-service-from-loose-xaml-with

    or here

    http://social.msdn.microsoft.com/Forums/fi-FI/wfprerelease/thread/731384b6-1be5-452f-95b5-4935dee29fb4


    There are two different ways which should solve the problem.

    Way 1: Edit your XAML file as a solution item, not as part of a project. This will change the format that Visual Studio uses when serializing the XAML namespace from

    "clr-namespace:RuleActivities.Executor"

    to

    "clr-namespace:RuleActivities.Executor;assembly=RuleActivities"

    or something similar, the important bit is that it will no longer have an implicit local assembly assumption like it does when you edit the XAML file within a project.

    Way 2: Continue to edit your XAML file as a project item. In your code which loads the XAML file for execution, provide a XamlReader to the ActivityXamlServices.Load(XamlReader, ...) method overload, and on that xaml reader you must have XamlReaderSettings.LocalAssembly = (assembly of projet where Workflow Xaml is defined).

    Tim

    • Marked as answer by HeatherB.rsa Thursday, November 4, 2010 8:43 PM
    Monday, November 1, 2010 5:24 PM
    Moderator

All replies

  • Make sure that the DLL that contains the type to be loaded is loaded into the GAC, or is in the same folder as the executable.
    Tuesday, October 26, 2010 4:02 PM
    Moderator
  • The dll is in the host's bin folder and I know the dll is accessible because the activity that is executing when the error is thrown is in the same assembly as the activity whose type is listed as unknown.
    Tuesday, October 26, 2010 5:43 PM
  • can you paste me your sample code so I can investigate for you?

    and you may also refer to this thread to check whether you you have added the other assembly to VisaulBasicSetting

    http://social.msdn.microsoft.com/Forums/en/wfprerelease/thread/4679ddb6-f1a9-49c6-afc8-d9f56ce81d5c

     

    if this still can't solve you problem, please let me know.

    Wednesday, October 27, 2010 5:35 AM
  • I have a sample project I can send but it is too much to just paste the code.

    Thursday, October 28, 2010 2:10 PM
  • then can you send it to this mail address?

    sophy_yuye@hotmail.com

    Thursday, October 28, 2010 5:43 PM
  • Hi Heather,

    This error is coming during the XAML deserialization step, right? I would guess it may be about the format of your XAML file's namespaces. (And that possibly the local namespace convention is causing problems.) Could you paste the top node of one of the activity XAMLs which fails to load?

    Also which type does it say is unknown, and what is the assembly it is in?

    Tim

    Friday, October 29, 2010 5:07 PM
    Moderator
  • The error occurs when I try to use the workflow invoker to execute the activity.  I created a sample project to reproduce the issue.  In that project the error is System.Xaml.XamlObjectWriterException: Cannot create unknown type '{clr-namespace:RuleActivities.Executor}ExecuteChildValidator'.

    Below is the root node of the activity that fails to load.  As I stated above, I can run the ExecuteChildValidator activity without an error if I call it directly but when it is called from within another XAML activity, I get the error.

    <

     

     

    Activity mc:Ignorable="sap" x:Class="RuleActivities.Executor.ExecuteChildValidator" xmlns="http://schemas.microsoft.com/netfx/2009/xaml/activities" xmlns:b="clr-namespace:BusinessEntities;assembly=BusinessEntities" xmlns:c="clr-namespace:CommonActivities;assembly=CommonActivities" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:mv="clr-namespace:Microsoft.VisualBasic;assembly=System" xmlns:mva="clr-namespace:Microsoft.VisualBasic.Activities;assembly=System.Activities" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:s1="clr-namespace:System;assembly=System" xmlns:s2="clr-namespace:System;assembly=System.Xml" xmlns:s3="clr-namespace:System;assembly=System.Core" xmlns:s4="clr-namespace:System;assembly=System.ServiceModel" xmlns:sa="clr-namespace:System.Activities;assembly=System.Activities" xmlns:sad="clr-namespace:System.Activities.Debugger;assembly=System.Activities" xmlns:sap="http://schemas.microsoft.com/netfx/2009/xaml/activities/presentation" xmlns:scg="clr-namespace:System.Collections.Generic;assembly=System" xmlns:scg1="clr-namespace:System.Collections.Generic;assembly=System.ServiceModel" xmlns:scg2="clr-namespace:System.Collections.Generic;assembly=System.Core" xmlns:scg3="clr-namespace:System.Collections.Generic;assembly=mscorlib" xmlns:sd="clr-namespace:System.Data;assembly=System.Data" xmlns:sl="clr-namespace:System.Linq;assembly=System.Core" xmlns:st="clr-namespace:System.Text;assembly=mscorlib" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">

    Friday, October 29, 2010 8:28 PM
  • I received your mail but didn't get your sample project.

    can you try to resend it to me?

    Friday, October 29, 2010 8:51 PM
  • I resent the project.
    Monday, November 1, 2010 12:43 PM
  • Hi Heather,

    From the description and error message you provided, I think this is because of the XAML local-assembly namespace conventions, and is the same basic issue as here

    http://stackoverflow.com/questions/2330762/wf4-rc-cannot-create-unknown-type-when-loading-wf-service-from-loose-xaml-with

    or here

    http://social.msdn.microsoft.com/Forums/fi-FI/wfprerelease/thread/731384b6-1be5-452f-95b5-4935dee29fb4


    There are two different ways which should solve the problem.

    Way 1: Edit your XAML file as a solution item, not as part of a project. This will change the format that Visual Studio uses when serializing the XAML namespace from

    "clr-namespace:RuleActivities.Executor"

    to

    "clr-namespace:RuleActivities.Executor;assembly=RuleActivities"

    or something similar, the important bit is that it will no longer have an implicit local assembly assumption like it does when you edit the XAML file within a project.

    Way 2: Continue to edit your XAML file as a project item. In your code which loads the XAML file for execution, provide a XamlReader to the ActivityXamlServices.Load(XamlReader, ...) method overload, and on that xaml reader you must have XamlReaderSettings.LocalAssembly = (assembly of projet where Workflow Xaml is defined).

    Tim

    • Marked as answer by HeatherB.rsa Thursday, November 4, 2010 8:43 PM
    Monday, November 1, 2010 5:24 PM
    Moderator
  • Thanks for the links.  Loading with the XamlXmlReader and setting the LocalAssembly property did get rid of the error.  I was wondering if there is a way to get the assembly dynamically.  Is there a way to get a reference to the activity that called your custom code activity at runtime?
    Monday, November 1, 2010 6:25 PM
  • I have sent you back the modified code.
    Monday, November 1, 2010 7:26 PM
  • I'm not sure if I understand the question. Local assembly should point to the assembly which the namespace is in, but I don't think that depends on the activity calling your custom code activity.

    If you are having trouble figuring out which assembly to set as LocalAssembly, then I would suggest you try to use Way 1 instead, where assembly information is explicitly in the XAML.

    Tim

    Tuesday, November 2, 2010 5:25 PM
    Moderator