简体   繁体   中英

Could not load file or assembly 'System, Version=4.0.0.0, Culture=neutral' or one of its dependencies

At some point during development I got the following error message:

Could not load file or assembly 'System, Version=4.0.0.0, Culture=neutral' or one of its dependencies.

It's a WPF application in .NET 4.7.1. Several 3rd party nuget packages have been installed and it worked fine, until today.

I've added some application settings and added a static Settingshelper class to make it easier to get these settings:

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

There is a ConnectionString key/value pair in the app.config and the key/value pair was added using the properties window of the project. This generates the code:

    [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"]));
        }
    }

The exception is thrown on the return statement.

At first it compiled fine and no error was shown. After I changed a single line of code (simple string concatenation in some method) the error showed up at runtime. Reverting that line of code doesn't solve the problem.

The solution consists of the main project and several other projects (class libraries) where the main project references these included class libraries.

I've read Could not load file or assembly 'System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' or one of its dependencies but I don't have the mentioned file. I've checked the .sln and .csproj files but couldn't find references to old deleted files.

The only system difference is that I installed the debugger from Windows Software Development Kit because of a memory dump that I wanted to analyze. I've uninstalled and rebooted the machine, just in case.

I'm pretty new to C# and Visual Studio (not new to programming in general).

Edit: I've also removed and added the System reference in the main project. Removed and added the ConnectionString key value pair.

It looks like I found the problem. In the App.config the <sectionGroup name="applicationSettings"... has a PublicKeyToken property. This was somehow changed to a PublicPathToken . I have no idea why and how this was done.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

Related Question Could not load file or assembly 'System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=561934e089' or one of its dependencies Could not load file or assembly 'System.Web, Version=4.0.0.0, Culture=neutral' or one of its dependencies. Access is denied Could not load file or assembly 'System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' or one of its dependencies Could not load file or assembly 'System.Data.Linq, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' or one of its dependencies Could not load file or assembly 'System.Configuration, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies Could not load file or assembly 'System.IdentityModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' or one of its dependencies Could not load file or assembly 'System.Runtime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies Could not load file or assembly 'System.IO, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies Could not load file or assembly 'System.Web.Http.WebHost, Version=4.0.0.0, Culture=neutral, PublicKeyToken C#: Could not load file or assembly 'OpenPop, Version=2.0.4.369, Culture=neutral, PublicKeyToken=null' or one of its dependencies
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM