Niraj Bhatt – Architect's Blog

Ruminations on .NET, Architecture & Design

Issues using Workflow with Code Separation (.xoml)

There are many benefits creating a workflow with code separation. Standout feature is if you want Rehost the workflow you will need to supply the xoml file as the input (you can find Re-hosting sample here). Inspired by that I started with creating workflow with code separation model.

But it wasn’t long before I realized that this approach had some limitations.

1      You can’t have constructor in the code behind file. This is normally a area for initialization of properties. Not having one can cause issues. Fortunately I found a workaround to override a method called InitializeProperties which is part of base class called DependencyObject.

public partial class Workflow1 : SequentialWorkflowActivity


        protected override void InitializeProperties() // override here



            dataHelper = new DataHelper(); // look ma, put initialization here




2      You won’t be able to access the activities in the code behind. Let’s say you have a replicator activity & you want to access the current child data. But unfortunately intellisense won’t work in code behind. Remember that xoml file is parsed & compiled at the time of compilation only, unlike the default workflow with code model that creates a partial class at design time itself and inturn forces us to use InitalizeComponent method.
Error: activity.CurrentChildData[activity.CurrentIndex]; (Not possible to access your activity in codebehind)
There can be 2 solutions to this issue:

a.       Use the activities collection to retrieve activity. The collection anyways would be populated at runtime:
ReplicatorActivity replicatorActivity =

                (ReplicatorActivity) this.Activities[“myReplicatiorActivity”];

Object data = replicatorActivity.CurrentChildData[replicatorActivity.CurrentIndex];  

b.      Previous one although works fine & might be mandatory for couple of scenarios, but as a better approach you can use a activity’s handlers to assign required values to local variables. For instance to capture the current child data, I can create a property called Data & retrieve its value by hooking into Replicatior Activity’s ChildInitialized event handler.


public Object Data { get; set; } // Property here

private void replicatorActivity1_ChildInitialized(object sender, ReplicatorChildEventArgs e)


            Data = e.InstanceData; // Extract the value



Hope this helps 🙂 .

(Update: The second issue outlined by me above is more of ReSharper issue. You need to use VS.NET Intellisense instead of ReSharper’s to avoid it. But nevertheless, if you are moving your workflows to a non-workflow (e.g. Web App) project, my solution is still quite useful).

3 responses to “Issues using Workflow with Code Separation (.xoml)

  1. jatin August 19, 2008 at 8:39 pm

    your blog on Issues with Xoml file was great help.
    thank you so much.

  2. Pingback: Wishing you the best 2009 has to offer « Niraj Bhatt - Architect’s Blog

  3. tmack April 2, 2010 at 6:59 pm

    Firing up my first WF and had this question. Thanks for the info.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: