|
Greetings;
I have a simple .NET Console Task in which I'm trying to log exceptions to the FlatFile Text Listener. I'm building and running my application under Windows XP Professional Version 5.1 (Build 2600.xpsp_sp3_gdr.120504-1619 : Service Pack 3) using the
Enterprise Library 5.0 Framework. My application was created under Visual Studio 2010 and targets the .NET Framework 4. My application builds cleanly with no compile or link warnings, and the app.config file passes validation without any warnings
using the Enterprise Library V5 Configuration Tool.
My console task project references the following DLLs from the Enterprise Library, and all are from the same source location and of the same version:
Microsoft.Practices.EnterpriseLibrary.Common
Microsoft.Practices.EnterpriseLibrary.ExceptionHandling
Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging
Microsoft.Practices.EnterpriseLibrary.Logging
Microsoft.Practices.EnterpriseLibrary.Logging.Database
At the point I attempt to log a caught exception to the FlatFile using the Exception Handling Application block, I receive runtime exception being thrown from within the Microsoft Enterprise Library classes of type System.Configuration.ConfigurationErrorsException
with the error message "An error occurred creating the configuration section handler for exceptionHandling: Could not load file or assembly 'Microsoft.Practices.EnterpriseLibrary.ExceptionHandling, Version=5.0.505.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'
or one of its dependencies."
Using the debug version of the Enterprise Libary 5.0 code, the System.Configuration.ConfigurationErrorsException with the FileLoadException InnerException refrence is being thrown from within ExceptionPolicy.GetExceptionPolicy(Exception exception, string
policyName) method's catch (Exception ex) block. The following are the contents of the outter System.Configuration.ConfigurationErrorsException with the System.IO.FileLoadException InnerException reference:
Outter Exception:
? ex.GetType().ToString()
"System.Configuration.ConfigurationErrorsException"
? ex.Message
"An error occurred creating the configuration section handler for exceptionHandling: Could not load file or assembly 'Microsoft.Practices.EnterpriseLibrary.ExceptionHandling, Version=5.0.505.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of
its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040) (C:\\MyConsoleApp\\RunMyConsoleApp\\bin\\Debug\\RunMyConsoleApp.vshost.exe.Config line 6)"
? ex.StackTrace
"at System.Configuration.BaseConfigurationRecord.FindAndEnsureFactoryRecord(String configKey, Boolean& isRootDeclaredHere)
at System.Configuration.BaseConfigurationRecord.GetSectionRecursive(String configKey, Boolean getLkg, Boolean checkPermission, Boolean getRuntimeObject, Boolean requestIsHere, Object& result, Object& resultRuntimeObject)
at System.Configuration.BaseConfigurationRecord.GetSection(String configKey)
at System.Configuration.ClientConfigurationSystem.System.Configuration.Internal.IInternalConfigSystem.GetSection(String sectionName)
at System.Configuration.ConfigurationManager.GetSection(String sectionName)
at Microsoft.Practices.EnterpriseLibrary.Common.Configuration.SystemConfigurationSource.DoGetSection(String sectionName)
at Microsoft.Practices.EnterpriseLibrary.Common.Configuration.FileBasedConfigurationSource.GetSection(String sectionName)
at Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ContainerModel.ConfigSectionLocator.GetRegistrationsInternal(IConfigurationSource configurationSource, Func`3 registrationsAccessor)
at Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ContainerModel.ConfigSectionLocator.GetRegistrations(IConfigurationSource configurationSource)
at Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ContainerModel.CompositeTypeRegistrationsProviderLocator.<GetRegistrations>b__0(ITypeRegistrationsProvider l, IConfigurationSource cs)
at Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ContainerModel.CompositeTypeRegistrationsProviderLocator.<>c__DisplayClass5.<GetRegistrationsInternal>b__4(ITypeRegistrationsProvider l)
at System.Linq.Enumerable.<SelectManyIterator>d__14`2.MoveNext()
at Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ContainerModel.Unity.UnityContainerConfigurator.RegisterAllCore(IConfigurationSource configurationSource, ITypeRegistrationsProvider rootProvider)
at Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ContainerModel.ChangeTrackingContainerConfigurator.RegisterAll(IConfigurationSource configurationSource, ITypeRegistrationsProvider rootProvider)
at Microsoft.Practices.EnterpriseLibrary.Common.Configuration.EnterpriseLibraryContainer.ConfigureContainer(ITypeRegistrationsProvider locator, IContainerConfigurator configurator, IConfigurationSource configSource)
at Microsoft.Practices.EnterpriseLibrary.Common.Configuration.EnterpriseLibraryContainer.ConfigureContainer(IContainerConfigurator configurator, IConfigurationSource configSource)
at Microsoft.Practices.EnterpriseLibrary.Common.Configuration.EnterpriseLibraryContainer.CreateDefaultContainer(IConfigurationSource configurationSource)
at Microsoft.Practices.EnterpriseLibrary.Common.Configuration.EnterpriseLibraryContainer.CreateDefaultContainer()
at Microsoft.Practices.EnterpriseLibrary.Common.Configuration.EnterpriseLibraryContainer.SetCurrentContainerIfNotSet()
at Microsoft.Practices.EnterpriseLibrary.Common.Configuration.EnterpriseLibraryContainer.get_Current()
at Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.ExceptionPolicy.GetExceptionPolicy(Exception exception, String policyName)"
Inner Exception:
? ex.InnerException.GetType().ToString()
"System.IO.FileLoadException"
? ex.InnerException.Message
"Could not load file or assembly 'Microsoft.Practices.EnterpriseLibrary.ExceptionHandling, Version=5.0.505.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The located assembly's manifest definition does not match the assembly
reference. (Exception from HRESULT: 0x80131040)"
? ex.InnerException.StackTrace
"at System.Configuration.TypeUtil.GetTypeWithReflectionPermission(IInternalConfigHost host, String typeString, Boolean throwOnError)
at System.Configuration.RuntimeConfigurationRecord.RuntimeConfigurationFactory.Init(RuntimeConfigurationRecord configRecord, FactoryRecord factoryRecord)
at System.Configuration.RuntimeConfigurationRecord.RuntimeConfigurationFactory.InitWithRestrictedPermissions(RuntimeConfigurationRecord configRecord, FactoryRecord factoryRecord)
at System.Configuration.RuntimeConfigurationRecord.CreateSectionFactory(FactoryRecord factoryRecord)
at System.Configuration.BaseConfigurationRecord.FindAndEnsureFactoryRecord(String configKey, Boolean& isRootDeclaredHere)"
? ((System.IO.FileLoadException)ex.InnerException).FileName
"Microsoft.Practices.EnterpriseLibrary.ExceptionHandling, Version=5.0.505.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
Referencing the FileLoadException, the Enterprise Library assembly that could not be load, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.dll, has the following properties inside the Visual Studio properties tab:
(Name) Microsoft.Practices.EnterpriseLibrary.ExceptionHandling
Aliases: global
Copy Local: True
Culture:
Description: Enterprise Library Exception Handling Application Block
Embed Interop Types: False
File Type: Assembly
Idendity: Microsoft.Practices.EnterpriseLibrary.ExceptionHandling
Path: C:\EntLib50Src\bin\Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.dll
Resolved: True
Runtime Version: v2.0.50727
Specific Version: False
Strong Name: False
Version: 5.0.505.0
The Enterprise Library references in the app.config file are as follows:
<configSections>
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
<section name="loggingConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.LoggingSettings, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.505.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="true" />
<section name="exceptionHandling" type="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Configuration.ExceptionHandlingSettings, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling, Version=5.0.505.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="true" />
<section name="dataConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSettings, Microsoft.Practices.EnterpriseLibrary.Data, Version=5.0.505.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="true" />
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=4.3.1.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
</configSections>
The <exceptionHandling> definition inside the app.config for FlatFile Exception Logging is as follows:
<exceptionHandling>
<exceptionPolicies>
<add name="FlatFile Policy">
<exceptionTypes>
<add name="SystemException" type="System.SystemException, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
postHandlingAction="None">
<exceptionHandlers>
<add name="Flat File Exception Handler" type="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging.LoggingExceptionHandler, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging, Version=5.0.505.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
logCategory="FlatFileException" eventId="1000" severity="Error"
title="Enterprise Library Exception Handling" formatterType="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.TextExceptionFormatter, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling"
priority="0" />
</exceptionHandlers>
</add>
</exceptionTypes>
</add>
</exceptionPolicies>
</exceptionHandling>
In attempt to further identify the cause of the FileLoadException, I tried to analyze the Microsoft.Practices.EnterpriseLibrary.ExceptionHandling load error using
fuslogvw.exe, and have received the following entries specific to Microsoft.Practices.EnterpriseLibrary.ExceptionHandling:
*** Assembly Binder Log Entry (8/16/2012 @ 11:40:20 AM) ***
The operation failed.
Bind result: hr = 0x80070002. The system cannot find the file specified.
Assembly manager loaded from: C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\clr.dll
Running under executable C:\RunMyConsoleApp\RunMyConsoleApp\bin\Debug\RunMyConsoleApp.exe
--- A detailed error log follows.
=== Pre-bind state information ===
LOG: User = Highbury\ClockEndGooner
LOG: DisplayName = Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.resources, Version=5.0.505.0, Culture=en-US, PublicKeyToken=null
(Fully-specified)
LOG: Appbase = file:///C:/RunMyConsoleApp/RunMyConsoleApp/bin/Debug/
LOG: Initial PrivatePath = NULL
LOG: Dynamic Base = NULL
LOG: Cache Base = NULL
LOG: AppName = RunMyConsoleApp.exe
Calling assembly : Microsoft.Practices.EnterpriseLibrary.ExceptionHandling, Version=5.0.505.0, Culture=neutral, PublicKeyToken=null.
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: C:\RunMyConsoleApp\RunMyConsoleApp\bin\Debug\RunMyConsoleApp.exe.Config
LOG: Using host configuration file:
LOG: Using machine configuration file from C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\config\machine.config.
LOG: Policy not being applied to reference at this time (private, custom, partial, or location-based assembly bind).
LOG: Attempting download of new URL
file:///C:/RunMyConsoleApp/RunMyConsoleApp/bin/Debug/en-US/Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.resources.DLL.
LOG: Attempting download of new URL
file:///C:/RunMyConsoleApp/RunMyConsoleApp/bin/Debug/en-US/Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.resources/Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.resources.DLL.
LOG: Attempting download of new URL
file:///C:/RunMyConsoleApp/RunMyConsoleApp/bin/Debug/en-US/Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.resources.EXE.
LOG: Attempting download of new URL
file:///C:/RunMyConsoleApp/RunMyConsoleApp/bin/Debug/en-US/Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.resources/Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.resources.EXE.
LOG: All probing URLs attempted and failed.
*** Assembly Binder Log Entry (8/16/2012 @ 11:40:20 AM) ***
The operation failed.
Bind result: hr = 0x80070002. The system cannot find the file specified.
Assembly manager loaded from: C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\clr.dll
Running under executable C:\RunMyConsoleApp\RunMyConsoleApp\bin\Debug\RunMyConsoleApp.exe
--- A detailed error log follows.
=== Pre-bind state information ===
LOG: User = Highbury\ClockEndGooner
LOG: DisplayName = Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.resources, Version=5.0.505.0, Culture=en, PublicKeyToken=null
(Fully-specified)
LOG: Appbase = file:///C://RunMyConsoleApp/bin/Debug/
LOG: Initial PrivatePath = NULL
LOG: Dynamic Base = NULL
LOG: Cache Base = NULL
LOG: AppName = RunMyConsoleApp.exe
Calling assembly : Microsoft.Practices.EnterpriseLibrary.ExceptionHandling, Version=5.0.505.0, Culture=neutral, PublicKeyToken=null.
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: C:\RunMyConsoleApp\RunMyConsoleApp\bin\Debug\RunMyConsoleApp.exe.Config
LOG: Using host configuration file:
LOG: Using machine configuration file from C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\config\machine.config.
LOG: Policy not being applied to reference at this time (private, custom, partial, or location-based assembly bind).
LOG: Attempting download of new URL
file:///C:/RunMyConsoleApp/RunMyConsoleApp/bin/Debug/en/Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.resources.DLL.
LOG: Attempting download of new URL
file:///C:/RunMyConsoleApp/RunMyConsoleApp/bin/Debug/en/Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.resources/Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.resources.DLL.
LOG: Attempting download of new URL
file:///C:/RunMyConsoleApp/RunMyConsoleApp/bin/Debug/en/Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.resources.EXE.
LOG: Attempting download of new URL
file:///C:/RunMyConsoleApp/RunMyConsoleApp/bin/Debug/en/Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.resources/Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.resources.EXE.
LOG: All probing URLs attempted and failed.
*** Assembly Binder Log Entry (8/16/2012 @ 11:40:17 AM) ***
The operation was successful.
Bind result: hr = 0x0. The operation completed successfully.
Assembly manager loaded from: C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\clr.dll
Running under executable C:\RunMyConsoleApp\RunMyConsoleApp\bin\Debug\RunMyConsoleApp.exe
--- A detailed error log follows.
=== Pre-bind state information ===
LOG: User = Highbury\ClockEndGooner
LOG: DisplayName = Microsoft.Practices.EnterpriseLibrary.ExceptionHandling, Version=5.0.505.0, Culture=neutral, PublicKeyToken=null
(Fully-specified)
LOG: Appbase = file:///C:/RunMyConsoleApp/RunMyConsoleApp/bin/Debug/
LOG: Initial PrivatePath = NULL
LOG: Dynamic Base = NULL
LOG: Cache Base = NULL
LOG: AppName = RunMyConsoleApp.exe
Calling assembly : System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089.
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: C:\RunMyConsoleApp\RunMyConsoleApp\bin\Debug\RunMyConsoleApp.exe.Config
LOG: Using host configuration file:
LOG: Using machine configuration file from C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\config\machine.config.
LOG: Policy not being applied to reference at this time (private, custom, partial, or location-based assembly bind).
LOG: Attempting download of new URL
file:///C:/RunMyConsoleApp/RunMyConsoleApp/bin/Debug/Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.DLL.
LOG: Assembly download was successful. Attempting setup of file: C:\RunMyConsoleApp\RunMyConsoleApp\bin\Debug\Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.dll
LOG: Entering run-from-source setup phase.
LOG: Assembly Name is: Microsoft.Practices.EnterpriseLibrary.ExceptionHandling, Version=5.0.505.0, Culture=neutral, PublicKeyToken=null
LOG: Binding succeeds. Returns assembly from C:\RunMyConsoleApp\RunMyConsoleApp\bin\Debug\Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.dll.
LOG: Assembly is loaded in default load context.
*** Assembly Binder Log Entry (8/16/2012 @ 11:40:20 AM) ***
The operation failed.
Bind result: hr = 0x80131040. No description available.
Assembly manager loaded from: C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\clr.dll
Running under executable C:\RunMyConsoleApp\RunMyConsoleApp\bin\Debug\RunMyConsoleApp.exe
--- A detailed error log follows.
=== Pre-bind state information ===
LOG: User = Highbury\ClockEndGooner
LOG: DisplayName = Microsoft.Practices.EnterpriseLibrary.ExceptionHandling, Version=5.0.505.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
(Fully-specified)
LOG: Appbase = file:///C:/RunMyConsoleApp/RunMyConsoleApp/bin/Debug/
LOG: Initial PrivatePath = NULL
LOG: Dynamic Base = NULL
LOG: Cache Base = NULL
LOG: AppName = RunMyConsoleApp.exe
Calling assembly : System.Configuration, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a.
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: C:\RunMyConsoleApp\RunMyConsoleApp\bin\Debug\RunMyConsoleApp.exe.Config
LOG: Using host configuration file:
LOG: Using machine configuration file from C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\config\machine.config.
LOG: Post-policy reference: Microsoft.Practices.EnterpriseLibrary.ExceptionHandling, Version=5.0.505.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
LOG: GAC Lookup was unsuccessful.
LOG: Attempting download of new URL
file:///C:/RunMyConsoleApp/RunMyConsoleApp/bin/Debug/Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.DLL.
LOG: Assembly download was successful. Attempting setup of file: C:\RunMyConsoleApp\RunMyConsoleApp\bin\Debug\Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.dll
LOG: Entering run-from-source setup phase.
LOG: Assembly Name is: Microsoft.Practices.EnterpriseLibrary.ExceptionHandling, Version=5.0.505.0, Culture=neutral, PublicKeyToken=null
WRN: Comparing the assembly name resulted in the mismatch: PUBLIC KEY TOKEN
ERR: The assembly reference did not match the assembly definition found.
ERR: Failed to complete setup of assembly (hr = 0x80131040). Probing terminated.
Based on the above information, any guideance or suggestions on how I can resolve this set of Microsoft.Practices.EnterpriseLibrary.ExceptionHandling errors and exceptions to log to a FlatFile would be greatly appreciated.
Thank you in advance for your time, help and patience.
|