Invalid Cast Exception: Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.LoggingSettings casting conflict

Topics: General discussion, Logging Application Block
Jan 28, 2015 at 7:43 PM
Hello,

I am working with an application which uses Enterprise Library 5.0.505.0. and our application references a third-party vendor solution which relies on Enterprise Library 3.1.0.0. Whenever the vendor solution tries to log something, we receive this exception.
Message: HandlingInstanceID: faec4655-7093-412f-91ea-60486b89bdac
An exception of type 'System.InvalidCastException' occurred and was caught.
---------------------------------------------------------------------------
01/28/2015 13:49:06
Type : System.InvalidCastException, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
Message : [A]Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.LoggingSettings cannot be cast to [B]Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.LoggingSettings. Type A originates from 'Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.505.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' in the context 'Default' at location 'T:\..........\EntLib5\Microsoft.Practices.EnterpriseLibrary.Logging.dll'. Type B originates from 'Microsoft.Practices.EnterpriseLibrary.Logging, Version=3.1.0.0, Culture=neutral, PublicKeyToken=64de8a15871beee6' in the context 'Default' at location 'C:\Windows\assembly\GAC_MSIL\Microsoft.Practices.EnterpriseLibrary.Logging\3.1.0.0__64de8a15871beee6\Microsoft.Practices.EnterpriseLibrary.Logging.dll'.
Source : Microsoft.Practices.EnterpriseLibrary.Logging
Help link : 
Data : System.Collections.ListDictionaryInternal
TargetSite : Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.LoggingSettings GetLoggingSettings(Microsoft.Practices.EnterpriseLibrary.Common.Configuration.IConfigurationSource)
HResult : -2147467262
Stack Trace :    at Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.LoggingSettings.GetLoggingSettings(IConfigurationSource configurationSource)
   at Microsoft.Practices.EnterpriseLibrary.Logging.LogWriterStructureHolderCustomFactory.CreateObject(IBuilderContext context, String name, IConfigurationSource configurationSource, ConfigurationReflectionCache reflectionCache)
   at Microsoft.Practices.EnterpriseLibrary.Logging.LogWriterCustomFactory.CreateObject(IBuilderContext context, String name, IConfigurationSource configurationSource, ConfigurationReflectionCache reflectionCache)
   at Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ObjectBuilder.ConfiguredObjectStrategy.BuildUp(IBuilderContext context, Type t, Object existing, String id)
   at Microsoft.Practices.ObjectBuilder.SingletonStrategy.BuildUp(IBuilderContext context, Type typeToBuild, Object existing, String idToBuild)
   at Microsoft.Practices.ObjectBuilder.BuilderStrategy.BuildUp(IBuilderContext context, Type typeToBuild, Object existing, String idToBuild)
   at Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ObjectBuilder.ConfigurationNameMappingStrategy.BuildUp(IBuilderContext context, Type t, Object existing, String id)
   at Microsoft.Practices.ObjectBuilder.BuilderBase`1.DoBuildUp(IReadWriteLocator locator, Type typeToBuild, String idToBuild, Object existing, PolicyList[] transientPolicies)
   at Microsoft.Practices.ObjectBuilder.BuilderBase`1.BuildUp(IReadWriteLocator locator, Type typeToBuild, String idToBuild, Object existing, PolicyList[] transientPolicies)
   at Microsoft.Practices.ObjectBuilder.BuilderBase`1.BuildUp[TTypeToBuild](IReadWriteLocator locator, String idToBuild, Object existing, PolicyList[] transientPolicies)
   at Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ObjectBuilder.EnterpriseLibraryFactory.BuildUp[T](IReadWriteLocator locator, IConfigurationSource configurationSource)
   at Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ObjectBuilder.EnterpriseLibraryFactory.BuildUp[T](IConfigurationSource configurationSource)
   at Microsoft.Practices.EnterpriseLibrary.Logging.LogWriterFactory.Create()
   at Microsoft.Practices.EnterpriseLibrary.Logging.Logger.get_Writer()
   at Microsoft.Practices.EnterpriseLibrary.Logging.Logger.Write(LogEntry log)
   at Afs.Direct.Branch.Diagnostics.Trace(TraceSourceType source, String message, TraceEventType severity, Dictionary`2 traceProperties)
   at Afs.Direct.Branch.BCTraceListener.WriteLine(String message, String category)
   at System.Diagnostics.TraceInternal.WriteLine(String message, String category)
   at Afs.Direct.CaptureInterop.ApiAuditor.LogMessageVerbose(String message)
   at Afs.Direct.CaptureInterop.Client.DirectClientManager..ctor()
   at Services.ChequeScannerService.initialize()
The loggingConfiguration in our app.config file looks like so:
<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"/>
and for the vendor it looks like:
<section name="loggingConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.LoggingSettings, Microsoft.Practices.EnterpriseLibrary.Logging"/>
I have tried editing the vendor config file to refer to the specific version of the enterprise library with no luck. I have tried bindingRedirect also with no success.

I understand that the easiest solution is to have both our application and the vendor both running the same version of the EntLib, however, that is not a possibility.

Looking for a brief explanation of why this problem is occurring (why the vendor is trying to cast a 5.0 object to a 3.1 object) and any possible resolutions for either side.

Thank you,

Gerald