How to fix the error “Exception has been thrown by the target of an invocation.” when using the BRI resolver in the ESB Toolkit and BizTalk 2013

In BizTalk 2009 and BizTalk 2010, there are often problems when installing the ESB Toolkit but then it (almost) always works well. In BizTalk 2013 The BizTalk Server installer now provides the option of installing ESB Toolkit as well. The configuration process is also much simpler so you would think it’s now more integrated with BizTalk Server 2013. Unfortunately, that is not entirely true. Installation has indeed become easier but also there are some new bugs added!

A great feature of the ESB Toolkit is that you can use business rules to select an itinerary based on the content of a received message. But when you have configured an Itinerary Selector pipeline component in BizTalk 2013 to use a business rules policy to select the appropriate itinerary, you get the following error:

“Exception has been thrown by the target of an invocation.”
Exception has been thrown by the target of an invocation
 
On the BizTalk ESB Toolkit Forum you can see that other users also have this problem so it's starting to seem that this is a bug!
 

 

Identifying the exact error

The error “Exception has been thrown by the target of an invocation.” is to generic and doesn't help very much but combined with Error StackTrace you see which .dll file, the method and the object that creates the error. As is often your best friend is Reflector so let’s have a closer look at the “ResolverFactory.Create” method in the Microsoft.Practices.ESB.Resolver.dll.

Microsoft.Practices.ESB.Resolver.ResolverFactory.Create
 
Yeah but what now? Let's try to copy that piece of code into a new solution in Visual Studio and run and debug it.
TestTool
 
Ok, I can now see that an instance of the “Microsoft.Practices.ESB.Resolver.Unity.ResolveProvider” object is going to be created. That's a bit more information but combined with the Inner Exception, we know what's really going on.
 
InnerException: “Unrecognized element 'typeConfig'. (C:\Program Files (x86)\Microsoft BizTalk ESB Toolkit\esb.config line 153)”
InnerException
 

 

How to fix the bug

The “Microsoft.Practices.ESB.Resolver.Unity.ResolveProvider” object in the ESB Toolkit 2.2 uses the Microsoft Enterprise Library 5.0 and Unity 2.0. When you google/bing on “Unrecognized element 'typeConfig'.” and Unity, it becomes clear that Unity 2.0 uses a new streamlined configuration schema for configuring Unity. Therefore, the esb.config file from the ESB Toolkit must be modified.

The following adjustments should be made:

  • Remove the <typeConfig> element
  • Change the <typeAlias> element to <alias>
  • Change the <type> element to <register>.
  • Remove the <containers> elements and <types> elements.

For more information see The Unity Configuration Schema in Unity 2.0.

Changes in file: C:\Program Files (x86)\Microsoft BizTalk ESB Toolkit\esb.config
esb config
 

 

Testing the changes in the esb.config

I used the sample How to: Select an Itinerary Using a Business Rules Policy to test the changes, but first I changed the machine.config file to be able to see BizTalk ESB Toolkit trace output.

To enable the BizTalk ESB Toolkit trace switch, add the following <switches> element to the system.diagnostics section of the Machine.config file.
<system.diagnostics>
      <switches>
          <add name="BizTalkESBToolkit" value="4"/>
      </switches>
 </system.diagnostics>
 
Now when you receive a message in BizTalk you can see the trace output from the ESB Toolkit. In the last line you can see that the itinerary is found and added to the cache!
DebugView
 

 

Conclusion

These adjustments in the esb.config file are not exactly rocket science yet it has taken me a long time to find the exact error and make the proper adjustments because the original error message was to generic and you have to perform a lot of work to find out what's going wrong!

You can download the updated esb.config file here:
modified_EsbConfig.zip

About the author

Tomasso Groenendijk lives in Netherlands and is a senior integration consultant at Motion10. He has over 15 years’ experience in software development and software design. Tomasso is specialized in application integration with a strong interest in the Windows Azure cloud platform. In 2014, 2015 and 2016 Tomasso was awarded with the Microsoft Azure MVP award. He is an active contributor to the integration community through his work on his blog, MSDN samples, TechNet Wiki and also speaking on events.

 
 
 
MVP profile Tomasso Groenendijk
 
 
Sentinet Product Specialist
 
 
BizTalk360 Product Specialist

Month List