disneystar

I am using the WorkflowDesignerControl (WDC) to create an application to provide simple enduser workflow authoring.

I envision the application working something like nUint, where a user would point to a set of assemblies containing custom activities they wish to consume.  The application would then...

1) Load the assembly

2) Add any types derived from Activity as custom activities in the WDC Toolbox...

The problem I run into is that it seems difficult to add a custom activity at runtime.  The only way I could really do it was by tinkering with the SelfHostToolboxItem class and forcing it to specifically load my assemblies.

Howver, even when I do this, if I use the custom item on the design surface the WorkflowView ( ) refuses to display the activity.

Is there a better way



Re: Windows Workflow Foundation Consuming custom activities at runtime using the WorkflowDesignerControl

Angel Azcarraga - MSFT

Hi,

This post is pretty old, so I'm assuming a lot has changed for you since then. Please open a new post if you're still having issues.

Thanks!
Angel






Re: Windows Workflow Foundation Consuming custom activities at runtime using the WorkflowDesignerControl

AndyB1979

I have exactly the same application & problem (using the WorkflowDesignerControl sample as a base)

A workflow designer control gets a list of plugin DLLs to search for custom activities. Each activity in a DLL that derives from a specific interface is added to the toolbox. This works fine, however when dragging and dropping the toolbox item onto the workflow, the item is moved there, but does not render. If you save a workflow after dragging a custom item onto it, you can see the item in the xoml, but the workflow itself looks just like a blank sequential workflow.

The only way around this is to reference the plugin DLL in the target application - something I didnt want to do as this defeats the object of having plugins!

This is something to do with custom designers applied to the custom activities. Each activity has a [Designer] attribute applied to it. If I comment out the attribute and use the default designer, the custom activities render fine. Do I need to register these designer classes with the workflow viewer / Workflow designer control If so, how

Cheers,

AndyB





Re: Windows Workflow Foundation Consuming custom activities at runtime using the WorkflowDesignerControl

Aleksey Nagoga.

Andy, the workflow designer control uses the txt file where it keeps all the toolbox items. The simpliest solution for your problem is to reuse existing logic - just add the newly added reference to the text file and refresh the toolbox.



Re: Windows Workflow Foundation Consuming custom activities at runtime using the WorkflowDesignerControl

AndyB1979

Hi Aleksey,

Thanks for your reply. Yes I did originally use toolboxitems.txt to test the principle of adding / removing items from the toolbox and this worked fine. However the project I'm working on requires plugin DLLs containing custom activities to be loaded dynamically, allowing us to add / remove plugins without having to recompile the whole project.

Anyway, I've fixed the problem just by moving the plugin library from an arbitrary directory to the application startup directory. Using Assembly.LoadFile I can load DLLs dynamically, create instances of all custom activity objects that implement a certain "CustomActivity" interface and add them to the toolbox by modifying the contructors of WorkFlowDesignerControl &Toolbox to accept the custom activity objects & modifying the toolbox item class to populate by instance, not by type.

To get the custom activities to render on the workflow viewer, the plugin DLL just needs to be located in the Application startup directory: none of the assemblies in the application need to statically reference the plugin DLL. To change plugins you just have to add / remove plugin DLLs and modify a config file to specify which libraries are loaded, not recompile the whole project.

Apparently I can move plugins to a "Plugins" directory within the application root directory and modify App.Config to search this directory for referenced assemblies, separating out plugins from the application.

Regards,

AndyB

Edit: You can add paths to search using the following snippet in an App.Config file. If plugin libraries are located in the specified directory, rendering will work properly on the Workflow viewer

<configuration>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <!-- Specify plugins directory as "ApplicationStartup\\Plugins\\" -->
      <probing privatePath="Plugins"/>
    </assemblyBinding>
  </runtime>
</configuration>





Re: Windows Workflow Foundation Consuming custom activities at runtime using the WorkflowDesignerControl

Aleksey Nagoga.

Andy, thank you for the good and detailed post. I found the app.config change you posted especially useful.