我試圖通過從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
文件,但我不知道怎麼的方式。
10x。在根目錄下,它說無法打開configsource文件.. –
當你寫一個完整的路徑時會發生什麼? –
完全相同的錯誤:「configSource屬性必須是相對物理路徑」。我將它設置爲:configSource =「D:\ tfs \ QA - Automation \ Projects \ ReportAppeal \ ReportAppeal \ Config \ Environment.config –