【问题标题】:C# Recursive Dependency Not Being Found未找到 C# 递归依赖项
【发布时间】:2018-09-02 16:03:10
【问题描述】:

我正在为一个项目学习 C#,但在依赖项方面遇到了一些麻烦。基本上这里是如何设置的:

项目本身,一个名为 (XMLupdater) 的库,依赖于 NuGet 包。然后我有另一个项目用于测试上述库(我称之为 XMLtester)。这是我的测试项目解决方案,在 Visual Studio 中将库添加为依赖项: link bc I can't embed images yet

据我所知,这里一切正常,但我在运行时收到一条错误消息,提示找不到 NuGet 包。它是这样说的:

System.IO.FileNotFoundException: 'Could not load file or assembly 'XmlDiffPatch.Core, Version=1.0.1.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified.'

我已经尝试了我能想到的一切来解决这个问题,但归根结底是我对这种语言和 ide 没有太多经验,而且依赖关系有时真的很奇怪。我问了几个其他人都无济于事,所以我决定征求你们的明智建议。有什么帮助吗?

谢谢!

【问题讨论】:

  • 您需要查看需要哪些其他 *.dll 文件才能加载 XmlDiffPatch.Core.dll 您可以使用 .dot peek 或 Visual Studio 等工具查看这些文件是什么并将它们添加为对您的项目的引用

标签: c# visual-studio dependencies


【解决方案1】:

看来你有汇编版本问题。您的解决方案中引用的程序集的版本与错误消息中显示的版本不同。

有两种方法可以解决这种情况:

  1. 获取错误中显示的程序集的确切版本并添加对该版本的引用。
  2. 在配置文件中使用 bindingRedirect 来告诉编译器要查找哪个版本。

对于第二个选项,您可以在执行项目的配置文件中添加/更新<assemblyRedirect 元素。

<dependentAssembly>  
  <assemblyIdentity name="someAssembly"  
    publicKeyToken="32ab4ba45e0a69a1"  
    culture="en-us" />  
  <bindingRedirect oldVersion="1.0.0.0" newVersion="— add the actual version of the assembly referenced in your project —" />  
</dependentAssembly>  

使用属性newVersion 设置项目中引用的 XmlDiffPatch.Core 的版本。

您可以在此处找到有关它的更多详细信息:https://docs.microsoft.com/en-us/dotnet/framework/configure-apps/redirect-assembly-versions

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-03-17
    • 2019-02-24
    • 2021-06-16
    • 2017-09-18
    • 2013-08-26
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多