2017-07-17 2 views
1

Ich versuche, eine Konfigurationsdatei zu verwenden, indem ich dort von App.config richte. Ich habe in meiner Lösung einen Ordner mit dem Namen Config erstellt und eine neue Konfigurationsdatei mit dem Namen Environment.config erstellt.Configsource-Pfad, der falsch verwendet

Mein App.Config sieht wie folgt:

<?xml version="1.0" encoding="utf-8"?> 
<configuration> 
    <configSections> 
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" /> 
    <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 --> 
    </configSections> 
    <entityFramework> 
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" /> 
    <providers> 
     <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" /> 
    </providers> 
    </entityFramework> 
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" /></startup> 
    <runtime> 
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> 
     <dependentAssembly> 
     <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" /> 
     <bindingRedirect oldVersion="0.0.0.0-9.0.0.0" newVersion="9.0.0.0" /> 
     </dependentAssembly> 
    </assemblyBinding> 
    </runtime> 
    <appSettings configSource="Config/Environment.config"/> 
</configuration> 

und die Environment.config sieht wie die folgende:

<appSettings> 
    <add key="URL" value="http://foo.aspx"/> 
    </appSettings> 

Ich erhalte eine Fehlermeldung, die besagt:

Result Message:
OneTimeSetUp: System.Configuration.ConfigurationErrorsException : Configuration system failed to initialize ----> System.Configuration.ConfigurationErrorsException : The configSource attribute must be a relative physical path, so the '/' character is not allowed. (D:\tfs\QA - Automation\Projects\ReportAppeal\ReportAppeal\bin\Debug\ReportAppeal.dll.config line 22)

Ich habe versuchte von "/" zu "\" zu wechseln, bekam aber einen anderen Fehler.

Result Message:
System.Configuration.ConfigurationErrorsException : Unable to open configSource file 'Config\Environment.config'. (D:\tfs\QA - Automation\Projects\ReportAppeal\ReportAppeal\bin\Debug\ReportAppeal.dll.config line 22) TearDown : System.NullReferenceException : Object reference not set to an instance of an object.

Ich werde wahrscheinlich die Art und Weise ändern müssen ich die Leitung der Environment.config Datei, aber ich bin nicht sicher, wie.

Antwort

1

Wie der Fehler sagt:

The configSource attribute must be a relative physical path

So werden Sie Ihre Schlüssel zu einem physischen Pfad ändern müssen, nicht ein relativer:

<appSettings configSource="C:\Config\Environment.config"/> 

Oder nur unter der Wurzel verlassen:

<appSettings configSource="Environment.config"/> 
+0

10x. Unter der Wurzel sagt es nicht möglich, configsource Datei zu öffnen. –

+0

Was passiert, wenn Sie einen vollständigen Pfad schreiben? –

+0

Der genau gleiche Fehler: "Das ConfigSource-Attribut muss ein relativer physischer Pfad sein". Und ich setzte es zu sein: configSource = "D: \ tfs \ QA - Automatisierung \ Projects \ ReportAppeal \ ReportAppeal \ Config \ Environment.config –

Verwandte Themen