Solved

Microsoft Enterprise Library 6.0: ExceptionPolicyFactory does not create Exception Manager

Posted on 2013-12-17
3
2,380 Views
Last Modified: 2014-01-02
I started playing with Microsoft Enterprise Library 6.0 using .Net 4.5 and VS 2012.

I am trying to use the exception handling block and logging block to first log an exception and then replace the exception with another exception.

This is the configuration section:

<exceptionPolicies>
            <add name="ReplaceWithFriendlyMessage">
                <exceptionTypes>
                    <add name="All Exceptions" type="System.Exception, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
                        postHandlingAction="ThrowNewException">
                        <exceptionHandlers>
                <add name="Logging Exception Handler" type="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging.LoggingExceptionHandler, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging, Version=6.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
                              logCategory="General" eventId="100" severity="Error" title="Enterprise Library Exception Handling"
                              formatterType="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.TextExceptionFormatter, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling"
                              priority="0" />
                            <add name="Wrap Handler" type="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.WrapHandler, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling, Version=6.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
                                exceptionMessage="Unexpected Error Occurred" wrapExceptionType="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.ExceptionHandlingException, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling, Version=6.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
                        </exceptionHandlers>
                    </add>
                </exceptionTypes>
            </add>
</exceptionPolicies>

 

This is how the exception handling factory is used at initialization:

Dim config As IConfigurationSource = ConfigurationSourceFactory.Create()
Dim factory As ExceptionPolicyFactory = New ExceptionPolicyFactory(config)
exManager = factory.CreateManager

exManager is of the type ExceptionManager and defined as an instance variable of the form.

I noticed that the factory.CreateManager code returns a null object with the configuration defined above. So my code throws a null reference exception later when I call exManager.Process or exManager.HandleException.

If I comment out the logging exception handler section, the exception manager gets loaded and handles the exception using the wrap exception handler. So if I comment out this text, the code works fine.

<!--<add name="Logging Exception Handler" type="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging.LoggingExceptionHandler, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging, Version=6.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
                              logCategory="General" eventId="100" severity="Error" title="Enterprise Library Exception Handling"
                              formatterType="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.TextExceptionFormatter, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling"
                              priority="0" />-->

I am inclined to say something is wrong in the configuration of Logging Exception Handler. The configuration section was added using the Enterprise Library 6.0 configuration tool. I am not sure why Exception Policy Factory does not throw an exception if the configuration is incorrect. Also, I compared my configuration with several working samples on the internet and they are identical to my settings with the exception of an older version of Enterprise Library reference.

I'll retry this in Ent Library 5 and see if I can find out something. In the meantime, I'll really appreciate any help with this issue. Thanks in advance.
0
Comment
Question by:shekhar_shashi
  • 3
3 Comments
 
LVL 3

Accepted Solution

by:
shekhar_shashi earned 0 total points
ID: 39725211
I tried the same solution in Enterprise Library 5 and it worked fine. I did not use the factory class, just used ExceptionPolicy.HandleException but I noticed how the original exception was logged and then wrapped with a custom exception. The configuration is provided below.

<exceptionPolicies>
            <add name="LogAndReplacePolicy">
                <exceptionTypes>
                    <add name="All Exceptions" type="System.Exception, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
                        postHandlingAction="ThrowNewException">
                        <exceptionHandlers>
                            <add name="Logging Exception Handler" type="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging.LoggingExceptionHandler, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
                                logCategory="General" eventId="100" severity="Error" title="Enterprise Library Exception Handling"
                                formatterType="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.TextExceptionFormatter, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling"
                                priority="0" />
                            <add name="Wrap Handler" type="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.WrapHandler, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
                                exceptionMessage="Unexpected Error Occurred." wrapExceptionType="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.ExceptionHandlingException, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
                        </exceptionHandlers>
                    </add>
                </exceptionTypes>
            </add>
        </exceptionPolicies>
0
 
LVL 3

Author Comment

by:shekhar_shashi
ID: 39727384
0
 
LVL 3

Author Closing Comment

by:shekhar_shashi
ID: 39751529
The solution provided on MSDN worked for me.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Store results in vb.net 3 24
Help with consolidating excel files using VB.net 2 29
jquery tab header text 1 22
Install IIS7.5 on Windows Sever 2012 R2 4 23
It seems a simple enough task, yet I see repeated questions asking how to do it: how to pass data between two forms. In this article, I will show you the different mechanisms available for you to do just that. This article is directed towards the .N…
In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question