Friday, June 26, 2009

ESB Toolkit 2.0 Has A Surprise for Enterprise Library 4.1 Users

I use Enterprise Library 4.1 in a number of apps, and I'm glad that ESB Toolkit 2.0 uses it too. But I'm not so glad about the way ESBT handles its EntLib configuration. It does something the EntLib documents expressly say you should not do: tamper with EntLib configuration settings in machine.config.

When you install ESBT the MSI adds the following to machine.config:

<configSections>
...
<section name="enterpriseLibrary.ConfigurationSource" type="Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ConfigurationSourceSection, Microsoft.Practices.EnterpriseLibrary.Common, Version=4.1.0.0,Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
...
</configSections>

...

<enterpriseLibrary.ConfigurationSource selectedSource="ESB File Configuration Source">
<sources>
<add name="ESB File Configuration Source" type="Microsoft.Practices.EnterpriseLibrary.Common.Configuration.FileConfigurationSource, Microsoft.Practices.EnterpriseLibrary.Common, Version=4.1.0.0,Culture=neutral, PublicKeyToken=31bf3856ad364e35" filePath="C:\Program Files (x86)\Microsoft BizTalk ESB Toolkit 2.0\esb.config"/>
<add name="ESB SSO Configuration Source" type="Microsoft.Practices.ESB.SSOConfigurationProvider.SSOConfigurationSource, Microsoft.Practices.ESB.SSOConfigurationProvider, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" applicationName="ESB" description="ESB SSO Configuration" contactInfo="someone@microsoft.com" userGroupName="BizTalk Application Users" adminGroupName="BizTalk Server Administrators"/>
</sources>
</enterpriseLibrary.ConfigurationSource>

(On a 64-bit machine, this will happen in both 32-bit and 64-bit versions of machine.config.)

What this does is, it forces Enterprise Library to ignore your app.config and/or web.config files and look for configuration information exclusively in ESBT's default configuration source, which happens to be the file "C:\Program Files (x86)\Microsoft BizTalk ESB Toolkit 2.0\esb.config". Since you probably didn't put your EntLib configuration settings in esb.config, EntLib won't find your apps' configuration at all, and they will crash. For example, a call to DatabaseFactory.CreateDatabase("myDatabase") will throw "System.Configuration.ConfigurationErrorsException: The requested database myDatabase is not defined in configuration."

I posted this on Microsoft's ESBT Forum yesterday and got a prompt response that led to a solution. Enterprise Library still looks in your app./web.config first, so if you insert your own <enterpriseLibrary.ConfigurationSource> section there, Enterprise Library will honor it.

So in my web.config file I inserted the following:

<configSections>
...
<section name="enterpriseLibrary.ConfigurationSource" type="Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ConfigurationSourceSection, Microsoft.Practices.EnterpriseLibrary.Common, Version=4.1.0.0,Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
...
</configSections>

...

<enterpriseLibrary.ConfigurationSource selectedSource="Local File Configuration Source">
<sources>
<add name="Local File Configuration Source" type="Microsoft.Practices.EnterpriseLibrary.Common.Configuration.FileConfigurationSource, Microsoft.Practices.EnterpriseLibrary.Common, Version=4.1.0.0,Culture=neutral, PublicKeyToken=31bf3856ad364e35" filePath="web.config"/>
</sources>
</enterpriseLibrary.ConfigurationSource>

This causes Enterprise Library to look for my app's configuration settings in my web.config file once again, and thus my app works as it did before ESBT came along.

I'm even thinking that it's always a good idea to put a <enterpriseLibrary.ConfigurationSource> in every config file that uses Enterprise Library, since you never know when some joker is going to pull the same stunt as ESBT in machine.config.

This is not a totally joyous solution though, because the Enterprise Library Configuration Editor tool seems not to understand that different <enterpriseLibrary.ConfigurationSource> sections can exist in machine.config and web.config at the same time, and so it complains when I try to use it to edit my web.config.

For more details you can read the whole ESBT Forum thread here.

8 comments:

Preetham Reddy said...

Thanks for the info... That's really helpful...

--
Preetham Reddy Chamakura
http://preetham-reddy.com

Unknown said...

hi thanks for the Post.
i am facing a similar issue and just tried to follow your instructions but get the below error message

There is a duplicate 'enterpriseLibrary.ConfigurationSource' section defined.

any advice?

Ashith Raj said...

This post is really helpful.. binged this topic and got the answer really quick.. saved me a week of troubleshooting.

Koottukaran said...
This comment has been removed by the author.
Adam said...

I am also getting

Section or group name 'enterpriseLibrary.ConfigurationSource' is already defined

Nelson Giraldo said...

Excellent!! thanks for the help :D

Kian, Ting said...

I have the same issue after installation of ESB, and my

I have the following set up in my web.config and I use the web.config to point to another webEntLib.config for more detail configuration pertaining to application logging.















This is the webEntLib.config



































How do I set up enterprise library in IIS web config so that it refers to the web sites configuraiton and dll files instead of getting the ESB's enterprise logging settings ?

Kian, Ting said...

I have found a solution to the issue the answers is at http://stackoverflow.com/questions/39090193/esb-toolkit-and-enterprise-library-collision-with-iis-web-config/39091751#39091751

and the steps that I have taken to come to a fix/solution is available at the following link
https://social.msdn.microsoft.com/Forums/en-US/01187602-8235-4b2e-8038-81b3f775c601/esb-toolkit-and-enterprise-library-collision-with-iis-webconfig?forum=biztalkesb