Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Configsource path using wrongly

Tags:

I'm trying to use a config file by directing there from App.config. I have created a folder named Config inside my solution and created a new config file named Environment.config.

My App.Config looks as following:

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

and the Environment.config looks as the following:

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

I'm getting an error which says:

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)

I have tried to switch from "/" to "\" but got a different error.

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.

I'll probably need to change the way I'm directing the Environment.config file but I'm not sure how.

like image 487
JumpIntoTheWater Avatar asked Jul 17 '17 10:07

JumpIntoTheWater


1 Answers

As the error says:

The configSource attribute must be a relative physical path

So you will need to change your key to a physical path, not a relative one:

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

Or just leave it under the root:

<appSettings configSource="Environment.config"/>
like image 54
Koby Douek Avatar answered Sep 30 '22 01:09

Koby Douek