2017-07-17 98 views
1

我试图通过从App.config指向那里来使用配置文件。 我在解决方案中创建了一个名为Config的文件夹,并创建了一个名为Environment.config的新配置文件。使用错误的配置路径

App.Config看起来如下:

<?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> 

Environment.config看起来如下:

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

我得到它说的错误:

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)

我有试图从“/”切换到“\”,但得到了不同的错误。

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.

我可能会需要改变我指挥Environment.config文件,但我不知道怎么的方式。

回答

1

由于错误说:

The configSource attribute must be a relative physical path

所以,你需要将你的密钥更改为物理路径,而不是相对:

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

或让它在根目录下:

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

10x。在根目录下,它说无法打开configsource文件.. –

+0

当你写一个完整的路径时会发生什么? –

+0

完全相同的错误:“configSource属性必须是相对物理路径”。我将它设置为:configSource =“D:\ tfs \ QA - Automation \ Projects \ ReportAppeal \ ReportAppeal \ Config \ Environment.config –