Chris Richner

Currently I'm trying to re-host the workflow designer, who's not ;)

But I'm failling with each mdsn code sample when I try to load a custom xoml workflow. I end up with a NullReferenceException during the GetRootActivity() method or I see an empy diagram showing nothing but emptyness ;(

I know that there is TypeLoader service available, I've added my assembly to this typeloader before the WorkflowLoader tries to load (create instance of) the workflow and it's custom written activities.

I would like to load a xoml based workflow with custom activites inside the rehosted designer, what am I missing

Thanks




Re: Windows Workflow Foundation Designer re-hosting and custom activities inside xoml-> NullReferenceException during GetRootActivity()

kushals

Take a look at this sample - It should be able to load up your custom XOML workflow.

http://msdn2.microsoft.com/en-us/library/aa480213.aspx

Thanks,

Kushal.






Re: Windows Workflow Foundation Designer re-hosting and custom activities inside xoml-> NullReferenceException during GetRootActivity()

Chris Richner

Hi Kushal,

That's exactly one of the samples I'm referring to where I'm getting this exceptions.






Re: Windows Workflow Foundation Designer re-hosting and custom activities inside xoml-> NullReferenceException during GetRootActivity()

kushals

Can you send in the code of your XOML activity

Thanks,

Kushal.






Re: Windows Workflow Foundation Designer re-hosting and custom activities inside xoml-> NullReferenceException during GetRootActivity()

Chris Richner

Hi Kushals,

Here is the xoml document I like to load. It's composed with standard activities and custom activites contained in an custom assembly. WorkflowBase in the namespace ="http://basenet.ch/ActivityLibrary serves as SequentalWorkflowActitivy.

<ns0:WorkflowBase DataContext="{p1:Null}" x:Name="Workflow2" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/workflow" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:p1="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:ns0="http://basenet.ch/ActivityLibrary">

<ns0:NumericDataActivity DataKey="aha" x:Name="hallo" Value="0" StepSize="1" Action="Assignment" />

<PolicyActivity x:Name="policyActivity1">

<PolicyActivity.RuleSetReference>

<RuleSetReference RuleSetName="Rule Set2" />

</PolicyActivity.RuleSetReference>

</PolicyActivity>

<WhileActivity x:Name="whileActivity1">

<WhileActivity.Condition>

<RuleConditionReference ConditionName="Condition2" />

</WhileActivity.Condition>

<SequenceActivity x:Name="sequenceActivity1">

<IfElseActivity x:Name="ifElseActivity1">

<IfElseBranchActivity x:Name="ifElseBranchActivity1">

<IfElseBranchActivity.Condition>

<RuleConditionReference ConditionName="Condition1" />

</IfElseBranchActivity.Condition>

<ns0:ConsoleWriteLineActivity Message="ifa" TimeoutDuration="00:00:05" x:Name="ConsolteWriteline2" />

</IfElseBranchActivity>

<IfElseBranchActivity x:Name="ifElseBranchActivity2">

<ns0:ConsoleWriteLineActivity Message="Elsa" TimeoutDuration="00:00:05" x:Name="ConsolteWriteline1" />

</IfElseBranchActivity>

</IfElseActivity>

<ns0:NumericDataActivity DataKey="aha" x:Name="numericDataActivity1" Value="0" StepSize="1" Action="Increment" />

</SequenceActivity>

</WhileActivity>

</ns0:WorkflowBase>

cheers

Chris






Re: Windows Workflow Foundation Designer re-hosting and custom activities inside xoml-> NullReferenceException during GetRootActivity()

kushals

We would also need your assemblies. Can you post your email address where I can reply to and then you can send me the assemblies as well.

Thanks,

Kushal.






Re: Windows Workflow Foundation Designer re-hosting and custom activities inside xoml-> NullReferenceException during GetRootActivity()

Chris Richner

Hi Kushal,

That's not possible due to copyright rules in my company. But I think that would lead to nowhere. It seems like everybody else on this planet is able to load custom designed xoml worfklows except me ;)

Is there any extra code one has to write to load custom workflows with the provided msdn code sample Or is it expected to work just out of the box

Thanks





Re: Windows Workflow Foundation Designer re-hosting and custom activities inside xoml-> NullReferenceException during GetRootActivity()

Jon Flanders

Chris - here are two things I always do to help with loading XAML:

Create a "wrapper" ITypeProvider. This can help you figure out what assemblies are trying to be loaded by the WorkflowMarkupSerializer. An example is at the end of my post.

Two - always wrap the code that uses WorkflowMarkupSerializer inside of a ServiceContainer - using this approach you can interogate the DesignerSerializationManager for the errors:

Activity a = null;

StringReader sr = new StringReader(xaml);

WorkflowMarkupSerializer wms = new WorkflowMarkupSerializer();

ServiceContainer sc = new ServiceContainer();

MyTypeProvider tp = new MyTypeProvider(sc);

sc.AddService(typeof(ITypeProvider), tp);

DesignerSerializationManager mgr = new DesignerSerializationManager(sc);

IList errors = null;

try

{

using (IDisposable disposable1 = mgr.CreateSession())

{

using (XmlReader reader2 = XmlReader.Create(sr))

{

a = wms.Deserialize(mgr, reader2) as Activity;

errors = mgr.Errors;

}

}

}

finally

{

sr.Close();

}

if ((a == null) || ((errors != null) && (errors.Count > 0)))

{

//there are xaml serialization errors

}

public class MyTypeProvider : ITypeProvider

{

#region ITypeProvider Members

public MyTypeProvider(IServiceProvider sp)

{

_contained = new TypeProvider(sp);

_contained.AddAssembly(Assembly.GetExecutingAssembly());

Assembly[] asms = AppDomain.CurrentDomain.GetAssemblies();

for (int i = 0; i < asms.Length; i++)

{

_contained.AddAssembly(asmsIdea);

}

_contained.TypeLoadErrorsChanged += new EventHandler(_contained_TypeLoadErrorsChanged);

_contained.TypesChanged += new EventHandler(_contained_TypesChanged);

}

void _contained_TypesChanged(object sender, EventArgs e)

{

if (this.TypesChanged != null)

this.TypesChanged.Invoke(sender, e);

}

void _contained_TypeLoadErrorsChanged(object sender, EventArgs e)

{

if (this.TypeLoadErrorsChanged != null)

this.TypeLoadErrorsChanged.Invoke(sender, e);

}

TypeProvider _contained = null;

public Type GetType(string name, bool throwOnError)

{

Type t = _contained.GetType(name, throwOnError);

return t;

}

public Type GetType(string name)

{

Type t = _contained.GetType(name);

return t;

}

public Type[] GetTypes()

{

Type[] t = _contained.GetTypes();

return t;

}

public System.Reflection.Assembly LocalAssembly

{

get { return _contained.LocalAssembly; }

}

public ICollection<System.Reflection.Assembly> ReferencedAssemblies

{

get { return _contained.ReferencedAssemblies; }

}

public IDictionary<object, Exception> TypeLoadErrors

{

get { return _contained.TypeLoadErrors; }

}

public event EventHandler TypeLoadErrorsChanged;

public event EventHandler TypesChanged;

#endregion

}






Re: Windows Workflow Foundation Designer re-hosting and custom activities inside xoml-> NullReferenceException during GetRootActivity()

Chris Richner

Hi Jon,

Your code works like a charm. Thank you very much. Why isn't your code part of the msdn sample ;)