Workflow 4 and Visual Basic expressions

Note: This blog post is written using the .NET framework 4.0 Beta 2

When using Windows Workflow Foundation 4 you often need to enter expression in some activity property. The new thing is these expressions are all in the Visual Basic dialect regardless of what language you project is in. So when developing a project in C# the expressions are sill in Visual Basic.

Weird right?

Well not really when you think about it!

After all power business users are expected to be able to modify workflows. And guess what their favorite tools are. That would be Microsoft Excel and Word. And what do they use to create macros? Right Visual Basic for Applications is their language of choice.


So if they use VBA letting them enter VB into expression dialogs is a far more natural fit than having them use C#.


A case for the Delay activity

So lets take a look at the delay activity. This activity takes 1 input property Duration of type Time Span. So I guess that means our VBA power users are going to have to enter something like if they want to wait 5 seconds:


Now for some reason I suspect that is not the first thing they are going to type. In fact they are more likely to time something like “0:0:05” instead. Not very VB like right?

Well it turns out workflow is smart enough to realize it can convert the string literal to a Time Span and use this. So when our power users does the following it just works [:)]


Nice, I like this!


Enjoy WF4!



11 thoughts on “Workflow 4 and Visual Basic expressions

  1. I saw somewhere that WF team used VB for expressions because the VB team gave them an in-memory parser in time for .NET 4.0 RTM. That’s the main reason I think :).

  2. @cibrax,

    That on not the explanation I was given. And it would be a new experience where CSD reused something from another team. Normally they rebuild/reinvent everything as they believe they can do a far better job.

  3. Forcing everyone to use VB because it is more convenient for business people is the stupidest excuse I have ever heard. What about all the applications that have nothing to do with business? Being forced to write code in the .net language for amateurs sucks big time. If you set aside this really irritating issue the workflow team is doing a great job IMHO.

  4. It would be better to have an expression interpreter provider that to do the job. So everyone can write the expressions in the language that thay prefer, just changing/adding the provider in config file, just like memberships provider or something else.

  5. @Ernesto,

    I agree, the workflow should just store a parsed version of the expression and you should be able to edit it in whatever dialect works best for you. Unfortunately that isn’t the case for now. Lets hope they enable that some time in the future.

  6. @Ernesto,

    the workflow runtime is agnostic when it comes to expression languages, there are all the extensibility points to add in a parser, even an extension point to add a custom dialog/ visual editor for the expressions. It is possible to enable the scenario that you mention, where we could have a provider, it is just not something that we enable out of the box, nor do we have a designer that we ship for other languages besides vb (specifically referring to the expression text box).

    We’re working on a sample that shows how you could implement a different expression text box if you want to support a different language (and also require a parser, etc).

  7. Omg, this is probably the worst explanation I can ever imagine. Why MS deals with business users in technology for developers? Have you ever seen any business user who at least understands exception handling, compensation, transactions, persistence, services or event driven execution? How can people without solid knowledge of these key concepts modify WF? How many WF projects target on business users? I guess no more than 20%. But I understand it sounds great on marketing presentations.

  8. @Ladislav,

    I know the feeling. However that said there is some benefit to this. Having the workflow runtime to let users add to your app by rehosting the designer is not a bad idea by itself. The question is how practical this is in the real world. It remains to be seen.

    And there is nothing wrong with marketing. No really, it means we can get payed to do all the cool stuff we enjoy :-)

  9. Why in world VB ? I have been preparing myself for WF 4.0 for some time and now when I finally started to get my hands dirty , I found myself into completely different world.I have never programmed with VB and I have no idea whats the syntax for initializing Dictionary in VB(yes I can look into google for help but that’s too much).

    Maurice , Just let us know how much of knowledge of VB will be okay to get started with WF.

  10. Hi Pawan,

    Don’t worry about it. Its only VB expressions not complete functions so the difference isn’t that big. For the most case VB has some extra but optional behavior. There are a few thing different like && is “And” and || is “Or” and “\n” isn’t seen as a newline.


  11. I was about to start a WWF project then read this post about having to go back to VB. Match abandoned! What a crazy idea.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>