WF4 now has State Machine – let’s play!


Just after the .net 4.0 framework and VS10 were famously released without state machine, the activities team has also released the missing state machine activity onto codeplex. It’s available as both a user-friendly installable package and an open source download. Of course I’m going to download the source straight away and have a play with it. (First day I’ve seen the thing.)

http://wf.codeplex.com/releases/view/43586

Of course I’m interested in the source code too, more than the installed package. One thing I notice about the source straight away is that they are using the two rhyming assemblies, Microsoft.Activities.StateMachine and Microsoft.Activities.StateMachine.Design, to get runtime designer separation while still ensuring that the .Design dll can be loaded by the designer.

The third assembly there is a VS integration which lets the installer add the StateMachine to the VS10 toolbox. Looks like this source code should serve as a great example of how you can publish your activities for customers to use.

So what if you just want to try out the source code, build the activity, and play with it in VS without installing the package onto your machine? Happy to report it works, but there are a couple little weirdnesses with that – State and FinalState won’t show up in the toolbox. You can work around this by using copy/paste to copy existing states, or to create your own IActivityTemplateFactory for generating a more fully populated state machine.

First impressions

-I found it weird that you can’t see anything inside the states inside the state diagram
-I’m getting weird validation errors about Trigger being null that don’t make any sense to me. I don’t know how to edit the triggers, the Transitions I mean….

Aha! Light dawns:

To see the transition you have to double-click on the links between states:

image

And then you can see the detailed transition view:

image

Besides it taking me ages to find the trigger view, a couple other things bugged me about the experience so far, which I hope they will improve in future releases:

-Validation errors only show up on the StateMachine itself, it would be better if they were on the specific State with a validation problem.
-You have to double-click on everything inside it to see any of the logic of your state machine (except conditions, which aren’t really interesting)
-Can’t set breakpoints on states or transition links. Can only set breakpoints on activities within the states, or on transitions.
-This means that when hitting breakpoints, you only see breadcrumbed views into states, you really can’t see where you are in execution of the top level statemachine, even if you breadcrumb back out.

One more thing I’ll mention is when I tried building from source code inside VS, I got exceptions when I ran my simple test workflow! What’s going on?

System.Xaml.XamlObjectWriterException was unhandled
  Message=The invocation of the constructor on type 'ActivityLibrary1.Activity1' that matches the specified binding constraints threw an exception.
  Source=System.Xaml
  LineNumber=0
  LinePosition=0
  StackTrace:
       at MS.Internal.Xaml.Runtime.ClrObjectRuntime.CreateInstance(XamlType xamlType, Object[] args)
…snip…
  InnerException: System.IO.FileNotFoundException
       Message=Could not load file or assembly 'Microsoft.Activities.StateMachine.Design, PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified.

Well, it turns out that it’s really no big deal. My StateMachine assemblies are

1) not gac’d
2) not in the same folder as my Executable and ActivityLibrary1 test assemblies which I’m using to run the thing.

All I need to do is adjust the build output paths of my test assemblies to be in the same folder as state machine assemblies.


Comments (3)

  1. Conrad LaFuente says:

    Hi, it has been pretty quiet lately, when can we expect news on a CTP2, beta or even final release?

  2. Mohan says:

    Hi,

    I am having the same problem as explained above, the only difference is that I am using WF4 in my ASP.NET 4.0 application. Below is my project structure,

    1. Website

    2. BLL

    3. WF4.0

    4. DAL

    When i publish the website on the server, am getting the following error

    "Error: Sys.WebForms.PageRequestManagerServerErrorException: The invocation of the constructor on type 'Magnum.MagnumWorkflows.Activities.RegistrationActivity' that matches the specified binding constraints threw an exception."

    Please help me out in case how i can adjust the build output paths into same folder as when i publish all the assemblies will go into "bin" folder.

    Thanks,

    Mohan

  3. tilovell09 says:

    Hi Mohan,

    Is the rest of the error message also the same? Because the bit you pasted is not the bit which tells you you're having trouble finding the file. Just thought I should ask, in case it's something else.

    For an ASP.net website, if you add project references from your website to the project which has the RegistrationActivity, that project's assembly should be copied to the asp.net web project's output folder automatically, and also published to bin folder when you publish your project.

    If that's not working (checked the bin folder?), check whether the 'Copy Local' property on the project reference says true.

    Tim

Skip to main content