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'.
LVL 1
countrymeisterAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Miguel OzSoftware EngineerCommented:
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

0
countrymeisterAuthor Commented:
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>
0
countrymeisterAuthor Commented:
Ok, I figured out this issue appsettingsis not correct it should be appSettings. XML is case sensitive
0
Cloud Class® Course: Microsoft Office 2010

This course will introduce you to the interfaces and features of Microsoft Office 2010 Word, Excel, PowerPoint, Outlook, and Access. You will learn about the features that are shared between all products in the Office suite, as well as the new features that are product specific.

countrymeisterAuthor Commented:
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
0
Miguel OzSoftware EngineerCommented:
Actually, you have two errors and I solved the one you asked in this question. My points please.
0
countrymeisterAuthor Commented:
mas_oz2003
I appreciate you trying to help me, but I really do not think my initial config had two issues.
In this below config, if I just change appsettings to appSettings the config loads fine, can you please try that and let me know. I have not included the startup element you suggested.

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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
countrymeisterAuthor Commented:
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
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C#

From novice to tech pro — start learning today.