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

 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.

  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:

  1. Downloaded EntLib 2.0
  2. Executed .exe download
  3. Run Build Enterprise Library
  4. Run Copy Assemblies to Bin Folder
  5. Run Install Instrumentation
  6. Add assemblies to the registry
  7. Open VS2005/My Solution
  8. Added Error Handeling and Logging Application Block to bin directory which loaded:
    1. ErrorHandeling.dll
    2. Logging.dll
    3. Common.dll
    4. ObjectBuilder.dll
  9. 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."
       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)

Specialty Bakers, Inc.
10/12/2006 8:23:27 PM
asp.net.application-block 1007 articles. 0 followers. Follow

5 Replies

Similar Articles

[PageSpeed] 5

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

  1. When exceptions were thrown
  2. Which exception was thrown
  3. 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");

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.

Specialty Bakers, Inc.
10/13/2006 4:07:48 PM

Try addding this line to your web.config it might solve your problem:

<dataConfiguration defaultDatabase="YourConnectionString" />

5/31/2007 7:25:23 PM

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. 




4/3/2008 7:05:15 AM

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. ?


4/3/2008 10:21:31 AM

what dll did u include?

6/4/2008 9:44:17 PM

Similar Artilces:

The type 'Microsoft.Practices.EnterpriseLibrary.Common.Instrumentation.IInstrumentationEventProvider' is defined in an assembly that is not referenced. You must add a reference to assembly 'Microsoft.
Ok, I don't get why it's complaining about my "Database" object and when I mouse over it in VS 2008 it's saying it's of a different type in the Common namespace.  It's looking for the common assembly when the Database object should be of type Microsoft.EnterpriseLibrary.Data.Database instead for the following syntax in my class: Database db = DatabaseFactory.CreateDatabase(); In my .cs I have the following using statements and definitely have the right version and assemblies to match in my references of my project:#region Using directives using System;...

An unhandled exception of type 'System.Configuration.ConfigurationException' occurred in microsoft.practices.enterpriselibrary.configuration.dll
Hi All, I'm using Enterprise Library - January 2006 and VS.net 2005.(Web application.)Receiving the below error while using the Enterprise Library Data Access Block at this line of code and I'm new to Enterprise Library.public static IDataReader ExecuteReader(string spName, params object[] values) {return DatabaseFactory.CreateDatabase( _databaseName ).ExecuteReader( spName, values ); }  Error Message An unhandled exception of type 'System.Configuration.ConfigurationException' occurred in microsoft.practices.enterpriselibrary.configuration.dllAdditional informat...

AJAX Beta 2
Hi... I'm experiencing a problem with the new AJAX Beta 2. When I try and put the UpdateProgess on a simple page, I get the belowCould not load type 'Microsoft.Web.UI.UpdateProgress' from assembly 'Microsoft.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.TypeLoadException: Could not load type 'Microsoft.Web.UI.Up...

Cast from type ''''DBNull'''' to type ''''String'''' is not valid.
How do I avoid getting this error: Cast from type ''''DBNull'''' to type ''''String'''' is not valid. I am trying to get values from the database into a form for updating using a Datareader, SQL is set to allow nulls for certain fields as they are not required but the only way I can get the form to display is by adding a space in SQL. Is there another way around this? Check if it is equal to DBNull.Value first and if it is, don't do the cast.Stanley Tan theSpoke Blog Where in the code does it need to go? I am using the following and it's the profile that isn't always requi...

The type initializer for 'tags' threw an exception??
Hello I get the following error...  The type initializer for 'tags' threw an exception. Does anyone who what this mean, or what might be causing this? Heres the code on the page giving the error...protected void Page_Load(object sender, EventArgs e) { WebUsers user = new WebUsers(); if (!this.IsPostBack) { if (Session["user"] != null) { user = (WebUsers)Session["user"]; } else { Response.Redirect("Login.aspx"); ...

'ds.SqlCacheDependency' threw an exception of type 'System.NotSupportedException'
Hi guys, As a follow up on my previous question: http://forums.asp.net/t/1336003.aspx I would like to know if any of you have an answer to the problem with the SqlCacheDependency throwing an System.NotSupportedException when trying to update using an AccessDataSource? Thanks :) /Ole   Since the SqlCacheDependency is not supported by Access, any attempt to make use of it through an AccessDataSource control will result in a NotSupportedException: http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.accessdatasource.sqlcachedependency.aspx.  The mystery is why ...

TypeInitializationException: The type initializer for 'clGeneral' threw an exception.
Okay Here is what I did, I have done this 2 previous projects and it worked flawlessly.  It works on my local machine, but when I deploy it throws the above exception.  this project and the last project are hosted by the same company and are set-up the same (I think - default) I have a seperate class called clGeneral located in teh app_code directory. the clSecured is also located there.  The first class is nothing more than defining common variables like database connections and things like that.  The second I use to encode and decode items that I want to stor...

The type initializer for 'BLL.Customer' threw an exception.
What does this error mean??? No clue.........   In .NET, you can have instance constructors and you can also have a static constructor. The static constructor is used to initialize static variables or do other one-time setup for all instances of a class, usually. Static constructors are also called type initializers, and will be called before the first instance of the class is constructed (it appears to usually happen when you first call a method that needs to know about the type). To see the code that is throwing an exception, look at the code for the class mentioned. In C#, look f...

Length = 'requestStream.Length' threw an exception of type 'System.NotSupportedException'
 I cannot figure out why when I expand the requestStream variable that I see that error.  Here's my code:   ... request.Timeout = 30000; request.Method = "POST"; request.ContentType = "application/x-www-form-urlencoded"; // write data to stream byte[] requestBytes = Encoding.UTF8.GetBytes(request.ToString()); using (Stream requestStream = request.GetRequestStream()) { requestStream.Write(reque...

Unit test causes exception "The type initializer for 'XXX' threw an exception" when running code which accesses appSettings of the webconfig
I have a method which I want to unit test, the code inside that method accesses the appSetting to get the connectionString : System.Configuration.ConfigurationSettings.AppSettings["ConnectionString"].ToString(); this piece of code works fine , but when  I m doing the unit test to test the method, the above line gives the below exception :MyMethod threw exception:  System.TypeInitializationException: The type initializer for 'XXX' threw an exception. --->  System.NullReferenceException: Object reference not set to an instance of an object..  ...

The type initializer for 'System.Drawing.ToolboxBitmapAttribute' threw an exception
Hi,All of a sudden I started getting this nasty exception all over the place:The type initializer for 'System.Drawing.ToolboxBitmapAttribute' threw an exception. Some relevant observations:* The error started occuring a few hours after the last deployment to the live server, not immediately after. So it basically started occuring of its own accord.* We have recently moved to a new host (a VPS). The error only occurs on that server, not our local server nor at the old host's (which was a shared environment).* The problem is basically the same as this guys:http://w...

The type initializer for 'System.Drawing.ToolboxBitmapAttribute' threw an exception.
I get this stacktrace at my ExceptionManager. It is caught in the Global.asax, so the exception is unhandled by my code :( We have many visitors and customers. This error occurs at least once a week, and all websites in the same pool are down. Only solution for now is to reset the pool when the error occurs. I know there are more topics on this, and I know MicroSoft is aware of the bug but does not know what to do about it. The bug will still be in the 3.5 release. If anybody has a work around for the fix, or a solution which is acceptable and avoids my customers and visitors ...

Could not load file or assembly 'Microsoft.Practices.EnterpriseLibrary.Data, Version=, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies
 C#, VS2005, Webforms. **NOTE** This page loads fine when I "View in broswer" locally...but when I'm on our web server, below occursYesterday when I left work, my web app worked fine.  Today, I get this error: Could not load file or assembly 'Microsoft.Practices.EnterpriseLibrary.Data, Version=, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040) Description: An un...

Can't terminate an application in the 'except' portion of a 'try..except' [Edit]
I'm a long time Delphi 5 user, recently switched to Delphi XE... and I'm having trouble getting a program to terminate if an exception is raised. Here's the code: procedure TForm1.FormCreate(Sender: TObject); begin try DFCom.Open except showmessage('Invalid Com Port number'); application.Terminate; end; end; In this code, 'DFCom' is an async serial port device. If the exceptino occurs, I want to notify the user via the 'showmessage' mechanism, and then abort the program. When I run this (with an invalid port number assigned to...

Web resources about - E2.0 - The type initializer for 'Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.ExceptionPolicy' threw an exception - asp.net.application-block

Resources last updated: 12/7/2015 2:36:06 PM