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:
<div>Downloaded EntLib 2.0</div>
<div>Executed .exe download</div>
<div>Run Build Enterprise Library</div>
<div>Run Copy Assemblies to Bin Folder</div>
<div>Run Install Instrumentation</div>
<div>Add assemblies to the registry</div>
<div>Open VS2005/My Solution</div>
<div>Added Error Handeling and Logging Application Block to bin directory which loaded:</div>
<div>ErrorHandeling.dll</div>
<div>Logging.dll</div>
<div>Common.dll</div>
<div>ObjectBuilder.dll</div>
<div>Configured the Web.Config file via the Enterprise Library Configuation tool</div>
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)
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
<div>When exceptions were thrown</div>
<div>Which exception was thrown</div>
<div>How to handel the exception</div>
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.
"Enterprise Library 2.0""Exception Handing Block""CSS Friendly Control Adapters""System.Web.HttpException"
jason_m
Member
283 Points
81 Posts
E2.0 - The type initializer for 'Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Exceptio...
Oct 12, 2006 08:23 PM|LINK
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:
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)
Error "Enterprise Library 2.0" "Exception Handing Block"
Programmer
Specialty Bakers, Inc.
jason_m
Member
283 Points
81 Posts
Re: E2.0 - The type initializer for 'Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Exce...
Oct 13, 2006 04:07 PM|LINK
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
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
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.
"Enterprise Library 2.0" "Exception Handing Block" "CSS Friendly Control Adapters" "System.Web.HttpException"
Programmer
Specialty Bakers, Inc.
newbie06
Member
625 Points
458 Posts
Re: E2.0 - The type initializer for 'Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Exce...
May 31, 2007 07:25 PM|LINK
Try addding this line to your web.config it might solve your problem:
<
dataConfiguration defaultDatabase="YourConnectionString" />itsdinesh123
Member
8 Points
9 Posts
Re: E2.0 - The type initializer for 'Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Exce...
Apr 03, 2008 07:05 AM|LINK
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.
itsdinesh123
Member
8 Points
9 Posts
Re: E2.0 - The type initializer for 'Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Exce...
Apr 03, 2008 10:21 AM|LINK
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. ?
User73757
Member
26 Points
131 Posts
Re: E2.0 - The type initializer for 'Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Exce...
Jun 04, 2008 09:44 PM|LINK
what dll did u include?