Custom Activites with Re-Hosted Workflows  
Author Message
Steve Graber





PostPosted: Windows Workflow Foundation, Custom Activites with Re-Hosted Workflows Top

I'm trying to add custom activities to a re-hosted workflow. I am working with the WorkflowDesignerControl sample. I have created a custom activity which is a class that inherits from System.Workflow.ComponentModel.Activity. The custom activity is built as a dll assembly. I have included the custom activity assembly as a reference in the WorkflowDesignerControl assembly dll. I have added the custom assembly to ToollbarItems.txt with the following line:

XSLTActivities.AnXSLTActivity, XSLTActivities

In the WorkflowLoader, Initialize, I am adding the assembly reference to the ITypeProvider service using the following code:

typeProvider.AddAssemblyReference(typeof(XSLTActivities.AnXSLTActivity).Assembly.Location);

The custom activity appears correcly in the Toolbox and I can drag the custom activity onto the workflow. However, when I compile the workflow I get errors in the parsing of the xoml file that the type or namespace of 'XSLTActivites' could not be found (could be missing an assembly reference). Does anyone know how to correct this error I have tried the following:

I added the assembly reference to the CodeCompileUnit in the WorkflowLoad constructor using 2 different constructs:

codeBesideccu.ReferencedAssemblies.Add("XSLTActivites");

and
codeBesideccu.ReferencedAssemblies.Add(typeof(XSLTActivities.AnXSLTActivity).Assembly.Location);

In the same constructor, I also added the CodeNamespaceImport to the namespace imports using the following line:

ns.Imports.Add(new CodeNamespaceImport("XSLTActivities"));

This adds 'using XSLTActivities;' to the workflow cs file.

However, neither of these fixes the problem.

Does anyone know how to get the workflow compiler to find the assembly for my custom activity



Software Development for Windows Vista7  
 
 
BabyGBear





PostPosted: Windows Workflow Foundation, Custom Activites with Re-Hosted Workflows Top

Hiya Steve

I think the bit you are missing is in the CompileWorkflow method in the WorkflowDesignerControl.

Before the ForEach for the workflow loaders add this

List<Assembly> referencedAssemblies = new List<Assembly>();

referencedAssemblies.Add(Assembly.GetAssembly(typeof(XSLTActivities));

then pass the list to the ReflectionHelper.CompileWorkflowAssemblyFiles method.

If thats not it, come back and I'll have another look as I've got this working fine.



 
 
Steve Graber





PostPosted: Windows Workflow Foundation, Custom Activites with Re-Hosted Workflows Top

I found the CompileWorkflow method in the WorkflowDesignControl class. There is no 'ForEach' for the workflow loaders. The only 'ForEach' is 'foreach (CompilerError compilerError in results.Errors)'.

The CompileWorkflowAssemblyFiles method is not called in the CompileWorkflow method, instead it is calling 'WorkflowCompilerResults results = compiler.Compile(parameters, strArr);'.

I am using the WorkflowDesignerControl sample that I downloaded from the MSDN article 'Everything About Re-Hosting the Workflow Designer'. It appears that the version you have of the WorkflowDesignerControl is significantly different than the version I have, at least in the CompileWorkflow method.

Thank you for your help,

Steve


 
 
BabyGBear





PostPosted: Windows Workflow Foundation, Custom Activites with Re-Hosted Workflows Top

D'oh! Sorry, I'd forgotten how many changes I'd made to my version.

For yours you need to add the following:

parameters.ReferencedAssemblies.Add("YourAssembly.dll");

before the parameters are passed.