Enterprise Library w/Exception Shielding

Topics: General Discussion Forum, July and December Releases Forum
Feb 22, 2007 at 4:22 PM
I have installed the Enterprise Library January 2006. The dlls are all version 2.0.0.0
I have also installed the Service Factory which has a folder "Enterprise Library Binaries" where the dlls are all version 2.0.1.0.

I have written the ASMX WSSF HOL to include Exception Shielding using the 2.0.1.0 dlls.
Now the problem is when I run the "Enterprise Library Configuration" Utility it complains that it can not load the 2.0.1.0 assemblies because they are not in C:\Program Files\Microsoft Enterprise Library January 2006\bin. I can not copy them to that folder because it then complains it can not find the 2.0.0.0 version which I just overwrote. So I added the 2.0.1.0 version of the dll to the GAC and it no longer complains about loadint the Assemblies but the "Enterprise Library Configuration" Utility still does not display the Exception Handling nor the Logging sections of the web.config file.

Is there a 2.0.1.0 version of the Enterprise Library that I can not find on Microsoft web site?
If not why are the versions different?

I have the following errors:

1) Unable to cast object of type 'Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Configuration.ExceptionHandlingSettings' to type 'Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Configuration.ExceptionHandlingSettings'
2) The type CategoryFilter does not contain the ConfigurationElement TypeAttribute. (web.config line 101)
Which is
<logFilters>
<add name="Category" type="Microsoft.Practices.EnterpriseLibrary.Logging.Filters.CategoryFilter, Microsoft.Practices.EnterpriseLibrary.Logging" categoryFilterMode="AllowAllExceptDenied">
<categoryFilters/>
</add>
</logFilters>

The WebService runs correctly and the Exception Shielding works correctly.
Just not able to edit web.config with Enterprise Library Config Utility.

Any Ideas???
Feb 22, 2007 at 11:43 PM
You have a version of the Configuration utility included in the binaries that comes with WSSF that works with v2.0.1.0. This particular version (included only in WSSF) contains the medium trust patch http://www.codeplex.com/entlib/Release/ProjectReleases.aspx?ReleaseId=1339 and the binaries are signed. If you don't care about these changes, feel free to switch to v2.0.0.0 (Jan-2006) and things should work fine.

Charly
Feb 23, 2007 at 5:25 PM
New Issue on this front. SoapExceptionHandler

I am now using the correct version of the Enterprise Library Configuration utility 2.0.1.0
Everything works except for the following:

Trying to create the SoapExceptionHandler like in Refernce Implementation
<add name="SoapExceptionHandler" type="Microsoft.Practices.ServiceFactory.ExceptionHandling.SoapExceptionHandler, Microsoft.Practices.ServiceFactory.Asmx.ExceptionHandling, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" exceptionMessage="An error occurred while processing your request. Please contact technical support using the following identifier: {handlingInstanceID}"/>

Under New Exception Handler I get the following choices:
Custom Handler
Logging Handler
Replace Handler
Wrap Handler

I choose Custom Handler
Set Name = SoapExceptionHandler
Set Type to "Load an Assembly" and picked Microsoft.Practices.ServiceFactory.Asmx.ExceptionHandling
I get ERROR "There were no types found in the assembly 'Microsoft.Practices.ServiceFactory.Asmx.ExceptionHandling'
that implement or inherit from the base type 'Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.IExceptionHandler'."

Therefore How do you define this type of Exception Handler????

If I manually enter in to web.config

<add name="SoapExceptionHandler" type="Microsoft.Practices.ServiceFactory.ExceptionHandling.SoapExceptionHandler, Microsoft.Practices.ServiceFactory.Asmx.ExceptionHandling, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" exceptionMessage="An error occurred while processing your request. Please contact technical support using the following identifier: {handlingInstanceID}"/>

and then run the program it works correctly.

If I then try to load web.config file in Enterprise Library Configuration utility, I get error
"Object Reference not set to an instance of an object." and Exception Handling Application Block section disappears.

If I then remove the SoapExceptionHandler from config file the re-run utility it loads correctly with no errors.

Can you use SoapExceptionHandler in web.config file with Enterprise Library Configuration utility ?????

Thanks,
Mark
Feb 23, 2007 at 8:54 PM
Mark,

As you may have noticed, the SoapExceptionHandler actually does implement the IExceptionHandler interface from EntLib ExceptionHandler assembly.
The only thing that I noticed in SoapExceptionHandler was that the SoapExceptionHandlerData used in the ConfigurationElementTypeAttribute on that class is declared as internal. I don't know if this might be a restriction in EntLib ExceptionHandler but I would try changing the declaration of SoapExceptionHandlerData to public (the same goes for SoapHandlerAssembler class).
Other than that, everything seem to be standard for an exception handler.

Hope that helps,
Charly
Feb 23, 2007 at 9:28 PM
I made them both public and got the same error in EntLib Config Utility
when I tried creating custom handler.

"There were no types found in the assembly 'Microsoft.Practices.ServiceFactory.Asmx.ExceptionHandling'
that implement or inherit from the base type 'Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.IExceptionHandler'."


Have you been able to use the EntLib Config utility to create the Custom Handler using this dll?

Thanks,
Mark
Feb 27, 2007 at 4:01 PM
I made them both public as you suggested but got the same error in EntLib Config Utility when I tried creating custom handler.

I did get the EntLib Config Utility to work with a New Exception Handler "Custom Handler" for the SoapExceptionHandler. I got this to work by changing
ConfigurationElementType(typeof(SoapExceptionHandlerData))
public class SoapExceptionHandler : IExceptionHandler
to
ConfigurationElementType(typeof(CustomHandlerData))
public class SoapExceptionHandler : IExceptionHandler
This is in accordance with the EntLib Documentation:"Add the class attribute ConfigurationElementType. Specify the type CustomHandlerData as the attribute parameter."

The EntLib Config Utility then generates the web.config file correctly
<add type="Microsoft.Practices.ServiceFactory.ExceptionHandling.SoapExceptionHandler, Microsoft.Practices.ServiceFactory.Asmx.ExceptionHandling, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" name="SoapExceptionHandler" />

However now the code does not run correctly. At runtime get following exception:
Message: Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.ExceptionHandlingException:
Constructor on type 'Microsoft.Practices.ServiceFactory.ExceptionHandling.SoapExceptionHandler' not found. --->
System.MissingMethodException: Constructor on type 'Microsoft.Practices.ServiceFactory.ExceptionHandling.SoapExceptionHandler' not found.
at System.RuntimeType.CreateInstanceImpl(BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes)
at System.Activator.CreateInstance(Type type, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes)
at Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ObjectBuilder.CustomProviderAssembler`3.Assemble(IBuilderContext context, TConfiguration objectConfiguration, IConfigurationSource configurationSource, ConfigurationReflectionCache reflectionCache)
at Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ObjectBuilder.AssemblerBasedObjectFactory`2.Create(IBuilderContext context, TConfiguration objectConfiguration, IConfigurationSource configurationSource, ConfigurationReflectionCache reflectionCache)
at Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.ExceptionPolicyEntryCustomFactory.Create(IBuilderContext context, ExceptionTypeData objectConfiguration, IConfigurationSource configurationSource, ConfigurationReflectionCache reflectionCache)
at Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.ExceptionPolicyCustomFactory.CreateObject(IBuilderContext context, String name, IConfigurationSource configurationSource, ConfigurationReflectionCache reflectionCache)
at Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ObjectBuilder.ConfiguredObjectStrategy.BuildUp(IBuilderContext context, Type t, Object existing, String id)
at Microsoft.Practices.ObjectBuilder.SingletonStrategy.BuildUp(IBuilderContext context, Type typeToBuild, Object existing, String idToBuild)
at Microsoft.Practices.ObjectBuilder.BuilderStrategy.BuildUp(IBuilderContext context, Type typeToBuild, Object existing, String idToBuild)
at Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ObjectBuilder.ConfigurationNameMappingStrategy.BuildUp(IBuilderContext context, Type t, Object existing, String id)
at Microsoft.Practices.ObjectBuilder.BuilderBase`1.DoBuildUp(IReadWriteLocator locator, Type typeToBuild, String idToBuild, Object existing, PolicyList[] transientPolicies)
at Microsoft.Practices.ObjectBuilder.BuilderBase`1.BuildUp(IReadWriteLocator locator, Type typeToBuild, String idToBuild, Object existing, PolicyList[] transientPolicies)
at Microsoft.Practices.ObjectBuilder.BuilderBase`1.BuildUpTTypeToBuild(IReadWriteLocator locator, String idToBuild, Object existing, PolicyList[] transientPolicies)
at Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ObjectBuilder.EnterpriseLibraryFactory.BuildUpT(IReadWriteLocator locator, String id, IConfigurationSource configurationSource)
at Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ObjectBuilder.LocatorNameTypeFactoryBase`1.Create(String name)
at Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.ExceptionPolicy.GetExceptionPolicy(Exception exception, String policyName)
--- End of inner exception stack trace ---
at Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.ExceptionPolicy.GetExceptionPolicy(Exception exception, String policyName)
at Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.ExceptionPolicy.HandleException(Exception exceptionToHandle, String policyName)
at Microsoft.Practices.ServiceFactory.ExceptionHandling.ExceptionShieldingExtension.HandleException(Exception exception) in C:\WSSFREFASMX\ServiceFactory.ASMXExceptionHandling\Source\ExceptionShieldingExtension.cs:line 245


Any suggestions how to reconcile the two issues?

Have you been able to get EntLib Config utility to work and the code to run correctly at the same time?

Thanks,
Mark
Feb 27, 2007 at 7:03 PM
Never mind found the following documentation
Exception Handling in ASMX
Note:
The SoapExceptionHandler that comes with the exception shielding implementation cannot be configured using the Configuration Console and needs to be configured by manually editing the Web.config file.

Thanks for the help