c# - 无法加载文件或程序集 'System, Version=4.0.0.0, Culture=neutral' 或其依赖项之一

标签 c# wpf

在开发过程中的某个时刻,我收到以下错误消息:

无法加载文件或程序集“System, Version=4.0.0.0, Culture=neutral”或其依赖项之一。

它是 .NET 4.7.1 中的 WPF 应用程序。已经安装了几个第 3 方 nuget 包,并且运行良好,直到今天。

我添加了一些应用程序设置并添加了一个静态 Settingshelper 类,以便更容易地获取这些设置:

public static string ConnectionString => Properties.Settings.Default.ConnectionString;

app.config 中有一个ConnectionString 键/值对,该键/值对是使用项目的属性窗口添加的。这会生成代码:

    [global::System.Configuration.ApplicationScopedSettingAttribute()]
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
    [global::System.Configuration.DefaultSettingValueAttribute("Server=localhost;Database=xxxx;Uid=xxxx;Pwd=xxxx;")]
    public string ConnectionString {
        get {
            return ((string)(this["ConnectionString"]));
        }
    }

返回语句抛出异常。

起初它编译正常,没有显示任何错误。在我更改了一行代码(某种方法中的简单字符串连接)之后,错误出现在运行时。恢复该行代码并不能解决问题。

解决方案由主项目和几个其他项目(类库)组成,主项目引用这些包含的类库。

我读过 Could not load file or assembly 'System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' or one of its dependencies但我没有提到的文件。我检查了 .sln.csproj 文件,但找不到对旧的已删除文件的引用。

唯一的系统差异是我从 Windows 软件开发工具包安装了调试器,因为我想分析一个内存转储。我已经卸载并重新启动机器,以防万一。

我对 C# 和 Visual Studio 还很陌生(对一般编程来说并不陌生)。

编辑:我还在主项目中删除和添加了系统引用。删除并添加了 ConnectionString 键值对。

最佳答案

看来我找到了问题所在。在App.config <sectionGroup name="applicationSettings"...有一个 PublicKeyToken属性(property)。这以某种方式更改为 PublicPathToken .我不知道为什么以及如何做到这一点。

关于c# - 无法加载文件或程序集 'System, Version=4.0.0.0, Culture=neutral' 或其依赖项之一,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50873260/

相关文章:

c# - 如何对空枚举进行单元测试?

c# - 多次比较字符串

c# - Aws Sqs Consumer - 仅在可以立即处理消息时进行轮询

c# - 更改在 MVVM 模式中按下的特定键的 View

c# - 从方法外部取消 GetAsync 请求

WPF 文本换行与 WrapWithOverflow

c# - 单引号 (') and double quote (") ASP.NET 中的奇怪行为

c# - 如何将 ModelBinders 与存储在 OwinContext 中的 DbContext 一起使用?

c# - 合并 xps 文档使最后一个重复

c# - WPF 4.5 : How to create child thread and continue task to UI main thread?