With BizTalk Server 2010 the mapper got updated to a new version and one of the features was the possibility to use the mapper in Workflow Foundation. What happens if you try to use the mapper in Visual Studio 2012?

In Visual Studio 2012 there are some really nice new features for Workflow Foundation like annotations, C# in expressions and a lot more. Coming from a BizTalk world you might want to use the BizTalk mapper to map between two different types and now that it also is an activity the logical choice would try to use the BizTalk mapper in Workflows. This will most likely be fixed in BizTalk Server 2013, but then you have to wait for that upgrade and you might not want to upgrade your BizTalk just because you use a newer version of Workflow Foundation.

First part is to add the activity to the toolbox. It isn’t available just be choose items like you normally would, but if you browse the GAC you should find a DLL called Microsoft.ServiceModel.Channels.MapperActivy.

You can now add it to your Workflow, but when you click the BizTalkMapClass you get the following error:

Now to the workaround. Use Visual Studio 2010 to create a simple project where you use the mapper with the same input and output parameters and create the map you need. This should create a folder with the schema files, map file and a C# file. This folder you need to include in your Visual Studio 2012 project.

If you like you can change the namespace in the C# class file. Next you need to edit your Workflow in XAML mode (view code) and find the activity. Here you will find an attribute BizTalkMapClass and change that to the namespace and class in the C# from the Visual Studio 2010 folder:

<mscm:Mapper x:TypeArguments=”x:String, x:String” BizTalkMapClass=”HelpForUsingBizTalkMapperInVS2012.MapString

The last thing you need is to create a reference to the assembly Microsoft.XLANGs.BaseTypes which are located at “C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\PublicAssemblies\Microsoft.XLANGs.BaseTypes.dll”.

You project is now ready to go and should compile and run without any problems.

If you look closer at the items in the map created folder you will see that runtime it is actually only the C# code that is used. It contains the method to serialize the objects to XML and it contains the XSLT from the map. The map and the schemas are just there so that you can use the mapper in design time.

Random posts:

Help me, help you. You know how 😉 (click, click, click…) Or buy anything at Amazon. You get the same price, and I get a little bit of money.