J4N
J4N

Reputation: 20761

WorkflowInspectionServices throw me an XamlObjectWriterException in Workflow Foundation

For a simple prototype, I've to display a workflow file, and show on which step we are actually.

I found a sample here: http://msdn.microsoft.com/en-us/library/ee624139.aspx

Which does almost what I need.

In this sample, all action never wait on another action. So I created myself some very dummy Activity:

    public class WaitForNextCall :NativeActivity
{
    public const String WaitBookmark = "WaitingStep";


    #region Overrides of NativeActivity

    /// <summary>
    /// When implemented in a derived class, runs the activity’s execution logic.
    /// </summary>
    /// <param name="context">The execution context in which the activity executes.</param>
    protected override void Execute(NativeActivityContext context)
    {
        context.CreateBookmark(WaitBookmark);
    }

    protected override bool CanInduceIdle
    {
        get
        {
            return true;
        }
    }
    #endregion
}

Which seems to work. Since there I was creating my workflow directly in-code:

            return new Sequence()
                   {
                       Activities =
                           {
                               new WaitForNextCall(){DisplayName = "Step one"},
                               new WaitForNextCall(){DisplayName = "Step Two"},
                               new WaitForNextCall(){DisplayName = "Step Three"},
                               new WaitForNextCall(){DisplayName = "Step Four"}
                           }
                   };

The only problem with that is that I only see a "Sequence" element in the workflow designer.

So I created a xaml file which describe exactily the same thing, and I load it like this:

return ActivityXamlServices.Load("Workflows/WorkflowSample.xaml") as DynamicActivity;

But then I got this exception:

    System.Xaml.XamlObjectWriterException occurred
  Message=Impossible de créer le type inconnu '{clr-MyTestNameSpace.UserInterface.WorkflowItems}WaitForNextCall'.
  Source=System.Xaml
  LineNumber=0
  LinePosition=0
  StackTrace:
       à System.Xaml.XamlObjectWriter.WriteStartObject(XamlType xamlType)
       à System.Xaml.XamlWriter.WriteNode(XamlReader reader)
       [...] 

I double-checked, the file is present(it appears, that there is another error message when file isn't specified correctly). But it cannot find my "WaitFornextCall" class, which is used just several lines below.

I'm a little desesperate, I'm trying to understand how works Workflow foundations, but it's a little hard for now :(

Any advice will be welcome

Edit: I tried this to read the file, I don't have any exception in my constructor, but I don't know why, some libraries I'm using(ActiPro) seems to doesn't work anymore after the load:

        XamlReader reader = new XamlXmlReader("Workflows/WorkflowSample.xaml", new XamlXmlReaderSettings(){LocalAssembly =  System.Reflection.Assembly.GetExecutingAssembly()});

        return ActivityXamlServices.Load(reader);

Upvotes: 1

Views: 1310

Answers (2)

J4N
J4N

Reputation: 20761

I found the solution !!!!

YEAAAAAAAAAAAAAH :P

In fact the problem is that my Workflow was in the same project than my custom activity. And then visual studio doesn't indicate in which assembly the designer could found this activity, but when you read the file, this is an independant reader, which doesn't know you current assembly.

So having TWO different project, one containing the workflow, one containing activities, and then my workflow specify the assembly in which I can found the chart. Like this I can easily do a WorkflowDesigner.Load("myWorkflowHere.xaml"); without any problem!

Upvotes: 2

user1228
user1228

Reputation:

"Workflows/WorkflowSample.xaml" probably was built against a prior version of your code.

Delete it, rebuild your solution, then recreate it.

Upvotes: 0

Related Questions