简体   繁体   English

解决 .NET 项目中的 package 依赖项

[英]Resolving package dependencies in a .NET project

I've got a problem after I added the Logz.io log4net plugin ( Logzio.DotNet.Log4net ) to my .NET project:将 Logz.io log4net 插件 ( Logzio.DotNet.Log4net ) 添加到我的 .NET 项目后,我遇到了问题:

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简而言之, [log4net.Layout.SerializedLayout, log4net.Ext.Json]请求 log4net 版本2.0.9.0 ,而[Logzio.DotNet.Log4net.LogzioAppender, Logzio.DotNet.Log4net]请求 log4net 版本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.我以前从未见过这种情况,通常,NuGet 本身就做得很好。

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.理想情况下,让两者都使用 log4net 2.0.13.0会很棒,这是本文发布时的最新版本,但我很高兴学习如何解决这个问题。

Any ideas or solutions?有什么想法或解决方案吗? Thanks!谢谢!

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.更新到最新版本将解决该问题,因为当 Logz.io 不接受向后兼容性时,至少需要 log4net 版本2.0.12.0

A few days back I also had faced alike issues while most of the packages are updating after the ms vs 2022 final release!几天前,我也遇到了类似的问题,而大多数软件包在 ms vs 2022 最终版本之后都在更新!

Figured it out of course minutes after posting.发布后几分钟就理所当然地想出来了。 The trick was to trust in NuGet.诀窍信任 NuGet。 Somehow through my tinkering I got mixed up versions.不知何故,通过我的修补,我得到了混淆的版本。 So the solution was the following:所以解决方案如下:

  1. Right click solution -> Manage NuGet Packages右键解决方案 -> Manage NuGet Packages
  2. Uninstall log4net , log4net.Ext.Json , and Logzio.DotNet.Log4net卸载log4netlog4net.Ext.JsonLogzio.DotNet.Log4net
  3. 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. NuGet 将采用最新的兼容版本,正如@yasir-arafat 所提到的,至少对于 Logzio package 来说,解决冲突是必需的。 In the end, I can confirm the following configuration (from my .csproj file) is working:最后,我可以确认以下配置(来自我的.csproj文件)正在运行:
<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" />

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM