gpt4 book ai didi

c# - 配置源路径使用错误

转载 作者:太空狗 更新时间:2023-10-30 01:14:12 26 4
gpt4 key购买 nike

我正在尝试通过从 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 文件的方式,但我不确定该怎么做。

最佳答案

如错误所述:

The configSource attribute must be a relative physical path

因此您需要将 key 更改为物理路径,而不是相对路径:

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

或者直接放在根目录下:

<appSettings configSource="Environment.config"/>

关于c# - 配置源路径使用错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45142297/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com