c# - 找不到文件或程序集“System.Runtime, Version=4.1.2.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a”或对它的依赖
问题描述
操作系统:Win10 - IDE:VS17 (2022) - 目标:控制台应用程序 .NET Framework 4.6.1
因此,在安装和卸载名为 vanara.pinvoke.mpr 的 Nuget 包后,我遇到了一个相当奇怪的行为。首先,一切都奏效了。但是当我试图打开我的数据库连接时
Connection.Open() (MySQLConnector v4.0.30319)
我总是得到这个例外:
The file or assembly "System.Runtime, Version=4.1.2.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" or a dependency on it was not found. The system cannot find the specified file.": "System.Runtime, Version=4.1.2.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
在我的 Parser.exe.config 中,我在 System.Runtime 及其指定的版本中找到了这个:
<dependentAssembly>
<assemblyIdentity name="System.Runtime.Extensions" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.1.2.0" newVersion="4.1.2.0" />
</dependentAssembly>
所以似乎即使指定了正确的版本,编译器也找不到正确的版本。
因此,我查看了我的项目中的包文件夹,并找到了文件夹“System.Runtime.4.1.2”,所以它应该可以工作。我什至通过 NuGet 包重新安装了 System.Runtime 版本 4.1.2,但这也无济于事。
由于我没有使用 .Net Core 编程,因此我查看了许多其他不太符合我需求的问题,我无法真正弄清楚问题是如何发生的。
因此,根据我的理解,VS 正在将其依赖项的版本写入 exe.config,在运行时搜索它们并尝试从引用(=> 项目文件夹中的包文件夹)中获取它,还是我错了?
编辑: 我实际上是通过将 .csproj 文件中的“AutoGenerateBindingRedirects”标签的“true”更改为“false”来实现它的:
<PropertyGroup>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<GenerateBindingRedirectsOutputType>true</GenerateBindingRedirectsOutputType>
</PropertyGroup>
解决方案
推荐阅读
- facebook - Facebook Playable Preview 工具 zip 错误?
- ansible - 如何并行运行多个剧本?
- python - 函数在元组中查找双字母,输出如何通过双字母更改为字母顺序
- c++ - 我想将 sqlite3_exec() 函数的返回值存储在一个变量中。请帮助我如何做到这一点
- swift - 从数据库下载图像?迅速
- java - 更改每个备用字符的大小写
- pagespeed-insights - 谷歌页面速度洞察中的 Facebook 像素脚本
- r - 从字符向量创建带有标识符的变量
- c++ - QtCreator 性能调优
- python - 如何检查列表是否仅包含布尔值