Link to home
Start Free TrialLog in
Avatar of countrymeister
countrymeister

asked on

Unable to read app.config in WPF application

I am getting the following error while trying to read an app.config file from my wpf application
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <appsettings>
    <add key="Environment" value="DEV"/>
  </appsettings>
<startup>
  <supportedRuntime useLegacyV2RuntimeActivationPolicy="true" version="v4.0" sku=".NETFramework,Version=v4.0"  />
</startup>
</configuration>

Open in new window



<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <appsettings>
    <add key="Environment" value="DEV"/>
  </appsettings>
<startup>
  <supportedRuntime useLegacyV2RuntimeActivationPolicy="true" version="v4.0" sku=".NETFramework,Version=v4.0"  />
</startup>
</configuration>
The invocation of the constructor on type XYZ that
                        matches the specified binding constraints threw an exception.' Line number '7' and line position '48'.
Avatar of Miguel Oz
Miguel Oz
Flag of Australia image

useLegacyV2RuntimeActivationPolicy  is an startup attribute, thus, your startup element must be modified as follows:
<startup useLegacyV2RuntimeActivationPolicy="true">
  <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"  />
</startup>

Open in new window

Avatar of countrymeister
countrymeister

ASKER

still getting the same error , here is the updated config file

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <appsettings>
    <add key="Environment" value="DEV"/>
  </appsettings>
  <startup useLegacyV2RuntimeActivationPolicy="true">
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"  />
  </startup>
</configuration>
Ok, I figured out this issue appsettingsis not correct it should be appSettings. XML is case sensitive
I've requested that this question be closed as follows:

Accepted answer: 0 points for countrymeister's comment #a39460511

for the following reason:

I found the solution myself
Actually, you have two errors and I solved the one you asked in this question. My points please.
ASKER CERTIFIED SOLUTION
Avatar of countrymeister
countrymeister

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I gave mas_oz2003 ample time to reply why he should be granted the points.
I also gave an example of my solution without his suggested code which works