Ich habe ein Problem. Ich brauche ein Programm in .NET Core (C#), die wie folgt verwenden, schreiben app.config:Verwenden von app.config in .Net Core
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section name="custom" type="ConfigurationSample.CustomConfigurationSection, ConfigurationSample"/>
</configSections>
<connectionStrings>
<add name="sampleDatabase" connectionString="Data Source=localhost\SQLExpress;Initial Catalog=SampleDatabase;Integrated Security=True"/>
</connectionStrings>
<appSettings>
<add key="sampleApplication" value="Configuration Sample"/>
</appSettings>
<custom>
<customConfigurations>
<add key="customSample" name="Mickey Mouse" age="83"/>
</customConfigurations>
</custom>
</configuration>
und ich schreibe:
string connectionString = ConfigurationManager.ConnectionStrings["sampleDatabase"].ConnectionString;
Console.WriteLine(connectionString);
// read appSettings configuration
string appSettingValue = ConfigurationManager.AppSettings["sampleApplication"];
Console.WriteLine(appSettingValue);
und es ist beispielsweise aus dem Internet, so dachte, ich würde Arbeit, aber ich bin Ausnahmen bekommen:
System.Configuration.ConfigurationErrorsException: 'Error Initializing the configuration system.'
Inner Exception
TypeLoadException: Could not load type 'System.Configuration.InternalConfigurationHost' from assembly 'CoreCompat.System.Configuration, Version=4.2.3.0, Culture=neutral, PublicKeyToken=null' because the method 'get_bundled_machine_config' has no implementation (no RVA).
ich über NuGet heruntergeladen - Install-Package CoreCompat.System.Configuration -Version 4.2.3-r4 -Pre und funktioniert immer noch nicht. Vielleicht kann mir jemand helfen?
Ich denke für .net-Core werden Sie JSON-Dateien für die Konfiguration verwenden. Schau darauf. – Phiter
In .NET Core verwenden Sie appsettings.json, nicht app.config. –
aber ich sagte über .Net Core und nicht ASP.Net Kern – Nju