Asked by:
E2.0 - The type initializer for 'Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.ExceptionPolicy' threw an exception

Question
-
User1550342124 posted
I am recieving the following error when I attempt to handel an exception. within a try/catch block I am throwing a simple exception to make sure I setup error checking correctly. When the error is caught and passed to the block I get this error.
try { throw new Exception("test error logging"); //... status = Status.Success; } catch (Exception e) { ExceptionPolicy.HandleException(e, "Report Exception Policy"); status = Status.Fail; }
This is what I have done so far:
-
Downloaded EntLib 2.0
-
Executed .exe download
-
Run Build Enterprise Library
-
Run Copy Assemblies to Bin Folder
-
Run Install Instrumentation
-
Add assemblies to the registry
-
Open VS2005/My Solution
-
Added Error Handeling and Logging Application Block to bin directory which loaded:
-
ErrorHandeling.dll
-
Logging.dll
-
Common.dll
-
ObjectBuilder.dll
-
-
Configured the Web.Config file via the Enterprise Library Configuation tool
I added the code above and I get
System.TypeInitializationException was unhandled by user code
Message="The type initializer for 'Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.ExceptionPolicy' threw an exception."
Source="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling"
TypeName="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.ExceptionPolicy"
StackTrace:
at Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.ExceptionPolicy.HandleException(Exception exceptionToHandle, String policyName)
at SBI.SalesReports.BLL.Report.GenerateReport() in c:\JMeckley\My Documents\Visual Studio 2005\WebSites\SalesReports\App_Code\BLL\Report.cs:line 61
at _Default.wizReportGenerator_FinishButtonClick(Object sender, WizardNavigationEventArgs e) in c:\JMeckley\My Documents\Visual Studio 2005\WebSites\SalesReports\StandardReports\Default.aspx.cs:line 102
at System.Web.UI.WebControls.Wizard.OnFinishButtonClick(WizardNavigationEventArgs e)
at System.Web.UI.WebControls.Wizard.OnBubbleEvent(Object source, EventArgs e)
at System.Web.UI.WebControls.Wizard.WizardChildTable.OnBubbleEvent(Object source, EventArgs args)
at System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args)
at System.Web.UI.WebControls.Button.OnCommand(CommandEventArgs e)
at System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument)
at System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument)
at System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument)
at System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)Thursday, October 12, 2006 4:23 PM -
All replies
-
User1550342124 posted
I have most of the the problem resolved. First, I included the ErrorHandeling.Logging.dll file which was missing. Then I began testing different scenarios including
-
When exceptions were thrown
-
Which exception was thrown
-
How to handel the exception
I found the following code will produce my desired results:
void Application_Error(object sender, EventArgs e) { // Code that runs when an unhandled error occurs Exception ex = Server.GetLastError(); if (!string.IsNullOrEmpty(ex.Message)) { ExceptionPolicy.HandleException(ex, "Unhandeled Exception Policy"); //Response.Redirect("Error/error.aspx"); } }
But why do I need the If statement? After further testing I believe I know what the problem is. A System.Web.HttpException is thrown at
System.Web.CachedPathData.GetConfigPathData(String configPath)\r\n at System.Web.CachedPathData.GetVirtualPathData(VirtualPath virtualPath, Boolean permitPathsOutsideApp)\r\n at System.Web.HttpContext.GetFilePathData()\r\n at System.Web.HttpContext.GetConfigurationPathData()\r\n at System.Web.HttpContext.GetRuntimeConfig()\r\n at System.Web.Configuration.RuntimeConfig.GetConfig(HttpContext context)\r\n at System.Web.ClientImpersonationContext.Start(HttpContext context, Boolean throwOnError)\r\n at System.Web.ClientImpersonationContext..ctor(HttpContext context)\r\n at System.Web.HttpApplication.OnThreadEnter()\r\n at System.Web.HttpApplication.ResumeSteps(Exception error)
This is actually thrown twice in a row. I am using the CSSControlAdapters to reformat TreeViewControls. The exceptions are only thrown on pages containing this control. This may also effect other adapters, currently I am only working with the TreeView. So now my next step is to figure out what is causing the errors.
Friday, October 13, 2006 12:07 PM -
-
User-192792487 posted
Try addding this line to your web.config it might solve your problem:
<
dataConfiguration defaultDatabase="YourConnectionString" />Thursday, May 31, 2007 3:25 PM -
User-254161470 posted
I am getting the similar error ..
I have included Microsoft.Practices.EnterpriseLibrary.ExceptionHandling;
using Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging;But still getting the same error.
Thursday, April 3, 2008 3:05 AM -
User-254161470 posted
This error as been resolved by Inncluding the .dll file of correct version ie. of 3.1 but I am coming acrosss one more error
The configuration for TraceListener named Database Log Destination is missing from configuration
Can some one please help. ?
Thursday, April 3, 2008 6:21 AM -
User-459090201 posted
what dll did u include?
Wednesday, June 4, 2008 5:44 PM