System.TypeInitializationException occurred in Logging.dll

Topics: Logging Application Block
May 3, 2007 at 5:08 AM
I created a WPF application with just a button in a window
In the button click event follwing code is written

{
LogEntry log = new LogEntry();
log.EventId = 300;
log.Message = "Sample message";
log.Categories.Add("UI Events");
log.Priority = 5;
Logger.Write(log);
}

"An unhandled exception of type 'System.TypeInitializationException' occurred in Microsoft.Practices.EnterpriseLibrary.Logging.dll

Additional information: The type initializer for 'Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ObjectBuilder.EnterpriseLibraryFactory' threw an exception."

Follwing are the steps create the app

1. Create new WPF application using visula studio2005 with WPF extensions
2. Add References C:\Program Files\Microsoft Enterprise Library 3.0 - April 2007\Bin\Microsoft.Practices.EnterpriseLibrary.common.dll and C:\Program Files\Microsoft Enterprise Library 3.0 - April 2007\Bin\Microsoft.Practices.EnterpriseLibrary.Logging.dll
3. In button click
private void click(object sender, System.EventArgs e)
{
LogEntry log = new LogEntry();
log.EventId = 300;
log.Message = "Sample message";
log.Categories.Add("UI Events");
log.Priority = 5;
Logger.Write(log);
}
4. Run the app and on clicking the button i get the exception

Is there anything wrong about what i am doing

Regards

Matt
May 3, 2007 at 2:14 PM
You also need to reference

Microsoft.Practices.ObjectBuilder.dll

in your application.

Regards,

Dave

_______________________________

David Hayden
Microsoft MVP C#