WCF Exception Shielding: assembly not found

Topics: Exception Handling Application Block
Nov 9, 2011 at 4:44 PM

Hi everyone,

Is it expected behaviour when the WCF Exception Shielding section in web.config is defined but no [ExceptionShielding] attribute in the code and when an unhandled excpetion occured in a OperationContarct then the follwoing error returned to the client:

An error occurred creating the configuration section handler for exceptionHandling: Could not load file or assembly 'Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.WCF, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

Nov 10, 2011 at 5:32 AM

That doesn't sound like an expected error.  Can you post the config and code that is causing the issue?

Thanks.

--
Randy Levy
Enterprise Library support engineer
entlib.support@live.com

Nov 10, 2011 at 12:23 PM
Edited Nov 10, 2011 at 12:26 PM

After further investigation we found out that this exception is thrown when any ExceptionPolicy.HandleException for other policies is called, thus, causing some ExceptionHandling block issue.

When the [ExceptionShielding] section in web.config is commented out then the other excpetion handling with ExceptionPolicy.HandleException works fine.
When the [ExceptionShielding] section is configured and [ExceptionShielding] attribute is placed on the sercive class we got the error below:

The server did not provide a meaningful reply; this might be caused by a contract mismatch, a premature session shutdown or an internal server error.

Before posting the code, a few questions:

1. EntLib V5 configurator gives a warning "Unable to find type" for Fault Contract Type. I saw other people complained on that configurator issue but everything worked fine for them. Using the configurator we can't configure Fault Contract Type properly. Our project structure is:

- MyContract.dll - contains service interface and data contracts. No references to EntLib
- MyService.dll - contains service implementation with exception shielding and references to all required EntLib blocks
- IISHost - contains all above and web.config (
The configuration was based on http://blogs.microsoft.co.il/blogs/bursteg/archive/2007/04/07/Shielding-WCF-Services-with-Exception-Handling-Application-Block-_2D00_-Part-1.aspx)

I wonder would this project structure work fine with ExceptionShielding? Why does the configurator give an error?

2. Is it correct to apply [ExceptionShielding] to the service class rather then to the service interface?

 

Nov 11, 2011 at 4:22 AM

miksh,

The behavior you describe makes sense.  It sounds like an assembly is missing (or the metadata is not what was expected).  You should verify that the Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.WCF.dll is deployed to a location where it can be resolved at runtime (e.g. bin directory).  If it is deployed verify that the version and public key match the values in the configuration file.  I.e. Version=5.0.414.0 and PublicKeyToken=31bf3856ad364e35.

In terms of the configuration tool the message that appears ("unable to find type") is a warning message so it can safely be ignored.  It just means that the configuration tool cannot locate the type.  To get rid of this warning you can place the assembly with the fault contract type in the same directory as the EntLibConfig.exe program.  Irrespective of the warning message you should still be able to add a type by selecting an assembly or manually entering the type FullName.

Your project structure looks fine.

You can definitely add the ExceptionShieldingAttribute to the service class.

--
Randy Levy
Enterprise Library support engineer
entlib.support@live.com

Nov 14, 2011 at 4:48 PM

Hmm... so we have a probem. All the required files in the bin folder. What would be the best option - publish code here or send it directly to you?

Forgot to mention that we have a WCF extension to handle validation excpetion (based on http://blogs.msdn.com/b/carlosfigueira/archive/2011/06/07/wcf-extensibility-ierrorhandler.aspx). Could it cause a conflict?

Also, would excpetion shielding work with ServiceBehaviorAttribute.IncludeExceptionDetailInFaults = both true & false?

Nov 14, 2011 at 10:46 PM

For exception shielding to work you need to set includeExceptionDetailInFaults to false.

--
Randy Levy
Enterprise Library support engineer
entlib.support@live.com

Nov 16, 2011 at 10:30 AM

Miksh,

 

I know you said that all required files are in the bin folder...but even so, could you use Reflector or something else to look at Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.WCF.dll dependencies. There are times that I have forgotten to include all Entlib dependencies in the bin, and have seen similar errors. Also, you could use Fusion Log Viewer to see which dependency is really not being loaded.

Nov 16, 2011 at 1:41 PM

Thanks, I am aware of EntLib dependencies so here what we have in Bin folder (note that everything else - data access, logging, exception handling - works fine)

Microsoft.Practices.EnterpriseLibrary.Common.dll
Microsoft.Practices.EnterpriseLibrary.Data.dll
Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.dll
Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging.dll
Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.WCF.dll
Microsoft.Practices.EnterpriseLibrary.Logging.Database.dll
Microsoft.Practices.EnterpriseLibrary.Logging.dll
Microsoft.Practices.ServiceLocation.dll
Microsoft.Practices.Unity.Configuration.dll
Microsoft.Practices.Unity.dll
Microsoft.Practices.Unity.Interception.dll

Perhaps, I need to try Fusion Log Viewer.

 

Nov 16, 2011 at 11:04 PM

miksh, I sent you a PM but I haven't heard back.  If you have a small-ish project that reproduces the issue maybe you could send it to me.

--
Randy Levy
Enterprise Library support engineer
entlib.support@live.com

Nov 28, 2011 at 4:22 PM

It appeared that Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.WCF.dll has been taken from the EntLib source code build and has not been signed so that caused the reference issue between EntLib dlls. Once the correct dll version is used, everything works as expected.

Thanks for help.