I've got a problem after I added the Logz.io log4net plugin (Logzio.DotNet.Log4net
) to my .NET project:
log4net:ERROR Failed to find type [log4net.Layout.SerializedLayout, log4net.Ext.Json]
System.IO.FileLoadException: Could not load file or assembly 'log4net, Version=2.0.9.0, Culture=neutral, PublicKeyToken=669e0ddf0bb1aa2a'. The located assembly's manifest definition does not match the assembly reference. (0x80131040)
File name: 'log4net, Version=2.0.9.0, Culture=neutral, PublicKeyToken=669e0ddf0bb1aa2a'
at System.RuntimeTypeHandle.GetTypeByName(String name, Boolean throwOnError, Boolean ignoreCase, StackCrawlMarkHandle stackMark, ObjectHandleOnStack assemblyLoadContext, Boolean loadTypeFromPartialName, ObjectHandleOnStack type, ObjectHandleOnStack keepalive)
at System.RuntimeTypeHandle.GetTypeByName(String name, Boolean throwOnError, Boolean ignoreCase, StackCrawlMark& stackMark, AssemblyLoadContext assemblyLoadContext, Boolean loadTypeFromPartialName)
at System.RuntimeType.GetType(String typeName, Boolean throwOnError, Boolean ignoreCase, 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.Repository.Hierarchy.XmlHierarchyConfigurator.CreateObjectFromXml(XmlElement element, Type defaultTargetType, Type typeConstraint)
log4net:ERROR Failed to create object to set param: layout
log4net:ERROR Could not create Appender [LogzioAppender] of type [Logzio.DotNet.Log4net.LogzioAppender, Logzio.DotNet.Log4net]. Reported error follows.
System.IO.FileLoadException: Could not load file or assembly 'log4net, Version=2.0.12.0, Culture=neutral, PublicKeyToken=669e0ddf0bb1aa2a'. The located assembly's manifest definition does not match the assembly reference. (0x80131040)
File name: 'log4net, Version=2.0.12.0, Culture=neutral, PublicKeyToken=669e0ddf0bb1aa2a'
at System.RuntimeTypeHandle.GetTypeByName(String name, Boolean throwOnError, Boolean ignoreCase, StackCrawlMarkHandle stackMark, ObjectHandleOnStack assemblyLoadContext, Boolean loadTypeFromPartialName, ObjectHandleOnStack type, ObjectHandleOnStack keepalive)
at System.RuntimeTypeHandle.GetTypeByName(String name, Boolean throwOnError, Boolean ignoreCase, StackCrawlMark& stackMark, AssemblyLoadContext assemblyLoadContext, Boolean loadTypeFromPartialName)
at System.RuntimeType.GetType(String typeName, Boolean throwOnError, Boolean ignoreCase, 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.Repository.Hierarchy.XmlHierarchyConfigurator.ParseAppender(XmlElement appenderElement)
In short, [log4net.Layout.SerializedLayout, log4net.Ext.Json]
is requesting log4net version 2.0.9.0
, while [Logzio.DotNet.Log4net.LogzioAppender, Logzio.DotNet.Log4net]
is requesting log4net version 2.0.12.0
So in this case I understand the problem clearly, but don't know how to resolve it. I've never seen this before, usually, NuGet does a good job by itself.
Ideally, it'd be great to get both to use log4net 2.0.13.0
, which is the latest version at the time of this post, but I'd be happy learning how I can resolve this issue in general.
Any ideas or solutions? Thanks!
CodePudding user response:
Updating to the latest version will resolve the issue as the minimum has been required log4net version 2.0.12.0
when the backward compatibility has not been entertained by Logz.io.
A few days I also had faced alike issues while most of the packages are updating after the ms vs 2022 final release!
CodePudding user response:
Figured it out of course minutes after posting. The trick was to trust in NuGet. Somehow through my tinkering I got mixed up versions. So the solution was the following:
- Right click solution ->
Manage NuGet Packages
- Uninstall
log4net
,log4net.Ext.Json
, andLogzio.DotNet.Log4net
- Reinstall all three. NuGet will take the latest compatible versions, which as @yasir-arafat mentioned, is needed to resolve the conflicts at least for the Logzio package. In the end, I can confirm the following configuration (from my
.csproj
file) is working:
<PackageReference Include="log4net.Ext.Json" Version="2.0.10.1" />
<PackageReference Include="log4net" Version="2.0.13" />
<PackageReference Include="Logzio.DotNet.Log4net" Version="1.0.13" />