log4mongo/log4mongo-net

FileLoadException: Could not load file or assembly 'log4net, Version=1.2.11.0,

Closed this issue · 2 comments

As soon as I'm adding

	<appender name="mongo" type="Log4Mongo.MongoDBAppender, Log4Mongo">
	</appender>
	<root>
		<level value="DEBUG" />
		<appender-ref ref="mongo" />
	</root>

to the log4net.config I'm getting this exception. Where does 1.2.11 comes from?
My refs:

	  <PackageReference Include="log4mongo-net" Version="2.2.0" />
	  <PackageReference Include="log4net" Version="2.0.8" />

from my .Net Standard 2.0 library launched from Windows Service

First Chance: System.IO.FileLoadException: Could not load file or assembly 'log4net, Version=1.2.11.0, Culture=neutral, PublicKeyToken=669e0ddf0bb1aa2a' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
File name: 'log4net, Version=1.2.11.0, Culture=neutral, PublicKeyToken=669e0ddf0bb1aa2a'

=== Pre-bind state information ===
LOG: DisplayName = log4net, Version=1.2.11.0, Culture=neutral, PublicKeyToken=669e0ddf0bb1aa2a
 (Fully-specified)
LOG: Appbase = file:///C:/Users/user/source/repos/xxx/src/xxx.Service.Windows/bin/Debug/
LOG: Initial PrivatePath = NULL
Calling assembly : Log4Mongo, Version=2.2.0.0, Culture=neutral, PublicKeyToken=null.
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: C:\Users\user\source\repos\xxx\src\xxx.Service.Windows\bin\Debug\xxx.Service.Windows.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: log4net, Version=1.2.11.0, Culture=neutral, PublicKeyToken=669e0ddf0bb1aa2a
LOG: Attempting download of new URL file:///C:/Users/user/source/repos/xxx/src/xxx.Service.Windows/bin/Debug/log4net.DLL.
WRN: Comparing the assembly name resulted in the mismatch: Major Version
ERR: Failed to complete setup of assembly (hr = 0x80131040). Probing terminated.

log4net:ERROR Could not create Appender [mongo] of type [Log4Mongo.MongoDBAppender, Log4Mongo]. Reported error follows.
System.IO.FileLoadException: Could not load file or assembly 'log4net, Version=1.2.11.0, Culture=neutral, PublicKeyToken=669e0ddf0bb1aa2a' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
File name: 'log4net, Version=1.2.11.0, Culture=neutral, PublicKeyToken=669e0ddf0bb1aa2a'
   at System.RuntimeTypeHandle.GetTypeByName(String name, Boolean throwOnError, Boolean ignoreCase, Boolean reflectionOnly, StackCrawlMarkHandle stackMark, IntPtr pPrivHostBinder, Boolean loadTypeFromPartialName, ObjectHandleOnStack type)
   at System.RuntimeTypeHandle.GetTypeByName(String name, Boolean throwOnError, Boolean ignoreCase, Boolean reflectionOnly, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean loadTypeFromPartialName)
   at System.RuntimeType.GetType(String typeName, Boolean throwOnError, Boolean ignoreCase, Boolean reflectionOnly, StackCrawlMark& stackMark)
   at System.Type.GetType(String typeName, Boolean throwOnError, Boolean ignoreCase)
   at log4net.Util.SystemInfo.GetTypeFromString(Assembly relativeAssembly, String typeName, Boolean throwOnError, Boolean ignoreCase)
   at log4net.Util.SystemInfo.GetTypeFromString(String typeName, Boolean throwOnError, Boolean ignoreCase)
   at log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ParseAppender(XmlElement appenderElement)

=== Pre-bind state information ===
LOG: DisplayName = log4net, Version=1.2.11.0, Culture=neutral, PublicKeyToken=669e0ddf0bb1aa2a
 (Fully-specified)
LOG: Appbase = file:///C:/Users/user/source/repos/xxx/src/xxx.Service.Windows/bin/Debug/
LOG: Initial PrivatePath = NULL
Calling assembly : Log4Mongo, Version=2.2.0.0, Culture=neutral, PublicKeyToken=null.
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: C:\Users\user\source\repos\xxx\src\xxx.Service.Windows\bin\Debug\xxx.Service.Windows.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: log4net, Version=1.2.11.0, Culture=neutral, PublicKeyToken=669e0ddf0bb1aa2a
LOG: Attempting download of new URL file:///C:/Users/user/source/repos/xxx/src/xxx.Service.Windows/bin/Debug/log4net.DLL.
WRN: Comparing the assembly name resulted in the mismatch: Major Version
ERR: Failed to complete setup of assembly (hr = 0x80131040). Probing terminated.

log4net:ERROR Appender named [mongo] not found.
53   [3] INFO  xxx.Service.ProcessingService (null) - Started...
gimmi commented

Hi @gusarov

It's because log4mongo currently depend on log4net 2.0.0 that contains log4net.dll 1.2.11.0 (they messed with versioning in the past years...).

The binding of the DLL fail because log4net has a strong name, and so .NET runtime require exact matching of the version. There should be no problems in using log4net 2.0.8, but you need to add a so-called binding redirect.

ok, thanks, looks like it settled out (I think I did redirections and forgot already about it)