Ich habe einen Windows-Dienst, der die Standardkonfiguration (servicename.exe.config) verwendet..NET Windows-Dienst - service.exe.config Probleme
Das sieht wie folgt aus:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
<section name="appSettings" type="System.Configuration.AppSettingsSection"/>
<section name="connectionStrings" type="System.Configuration.ConnectionStringsSection"/>
</configSections>
<connectionStrings>
<!-- Omitted -->
</connectionStrings>
<appSettings>
<!-- Omitted -->
</appSettings>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
<parameters>
<parameter value="mssqllocaldb" />
</parameters>
</defaultConnectionFactory>
<contexts>
<context type="NWatch.NWatchDbContext, NWatch.Entities">
<databaseInitializer type="NWatch.NWatchDbContextInitializer, NWatch.Entities" />
</context>
</contexts>
<providers>
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
</providers>
</entityFramework>
</configuration>
Wenn der Windows-Dienst gestartet wird, erhalte ich einen Fehler, der besagt, dass:
Abschnitts- oder Gruppenname ‚appSettings‘ bereits definiert ist. Updates auf Dies kann nur auf der Konfigurationsebene auftreten, wo es definiert ist. (C: \ root \ lib \ svc \ nwatchd \ nwatchd.exe.Config Linie 6)
Also, ich voran gehen und entfernen Sie die beiden folgenden von der config (da sie beide Wurffehler):
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
<section name="appSettings" type="System.Configuration.AppSettingsSection"/>
Jetzt bekomme ich die folgende Ausnahme:
Konnte nicht das Objekt des Typs 'System.Configuration.DefaultSection' zu Typ 'System.Configuration.AppSettingsSection' werfen.
public NWatchSystemConfiguration(string fileName)
{
var fileMap = new ConfigurationFileMap(fileName);
var configuration = ConfigurationManager.OpenMappedMachineConfiguration(fileMap);
Config = configuration;
AppSettingsSection AppSettings = configuration.AppSettings; // Exception occurs here
ConnectionStrings = configuration.ConnectionStrings;
Initialize();
}
Ich habe bereits genau das getan, was Sie oben erwähnt haben. Die zweite Ausnahme oben ist, was geworfen wird. – blgrnboy
Nein, Sie haben gesagt, dass Sie den Abschnitt EntityFramework entfernt haben. – Fanda