Solved

Reading the app.config file

Posted on 2006-11-14
18
954 Views
Last Modified: 2010-05-18
I have an MDI form and different child forms read database connection strings from the app.config file. I am unable to read a particular value from my app.cofig file and I keep getting this error.

An unhandled exception of type 'System.Configuration.ConfigurationException' occurred in system.dll

Additional information: '<', hexadecimal value 0x3C, is an invalid attribute character. Line 5, position 50.

I am reading it this way within a form load event

Dim getthis As String
getthis = ConfigurationSettings.AppSettings("test")

Here is what my app.config file looks like.

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
  <add key="test" value="result" />
  <add key ="result" value ="AP26E>M*,PL;G-{#9^{}c8AKM<,PL0i[(Di]OQ{#kKG3aRT0COG+UT{&_#%NA=@Mv" />
</appSettings>
</configuration>

Please assist.



0
Comment
Question by:Sirdots
  • 5
  • 4
  • 3
  • +2
18 Comments
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 17941394
if you remove the key "result" from the config file, does it still error out?

0
 

Author Comment

by:Sirdots
ID: 17941416
Yes. But I need the key "result" for something else. cant I have a lot of entries?
0
 
LVL 35

Expert Comment

by:YZlat
ID: 17941578
replace all characters with hexadecimal values
0
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 

Author Comment

by:Sirdots
ID: 17941584
What I think is happening right now is the encryption program I am using to encrypt my connection strings uses > signs characters as values of my connection string. The app.config does that like this because it is a special character. Do you know how I can handle this? I removed all the > signs and it started working.
0
 
LVL 35

Expert Comment

by:YZlat
ID: 17941658
replace < with &#60;

> with &#62;

etc.

 <add key ="result" value ="AP26E&#62;M&#42;&#44;PL&#59;G&#45;&#123;&#35;9&#94;&#123;&#125;c8AKM&#60;&#44;PL0i&#91;&#40;Di&#93;OQ&#123;&#35;kKG3aRT0COG+UT&#123;&#38;&#95;&#35;&#37;NA&#61;&#64;Mv" />
0
 
LVL 35

Expert Comment

by:YZlat
ID: 17941668
but first try

<add key ="result" value ="AP26E&#62;M*,PL;G-{#9^{}c8AKM&#60;,PL0i[(Di]OQ{#kKG3aRT0COG+UT{&_#%NA=@Mv" />
0
 
LVL 39

Expert Comment

by:appari
ID: 17942931
are you using VS 2005? if VS 2005 change the values from project properties, it automatically escapes the string values to a valid XML string.
if not using VS 2005, try the following string value, this is generated in VS 2005.
AP26E&gt;M*,PL;G-{#9^{}c8AKM&lt;,PL0i[(Di]OQ{#kKG3aRT0COG+UT{&amp;_#%NA=@Mv
0
 

Author Comment

by:Sirdots
ID: 17943097
Thanks Guys. I am using VS2003 and I am unable to make any modification to the encrypted value because I have a method that will decrypt it. One thing I discovered not too long ago is that Storing characters like <> and & is not allowed in xml. It will always give you problems. I removed all these and my program is working very well.

I appreciate all your help.
0
 
LVL 5

Expert Comment

by:DEEPESH
ID: 17944558
Sorry to ask but have you added refrence to system.configuration and imported it.

Try using this code, it works fine at my side

        Dim config As System.Configuration.Configuration
        config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None)
        Dim value As String
        value = ConfigurationManager.AppSettings("result")
        MsgBox(value)
0
 
LVL 5

Expert Comment

by:DEEPESH
ID: 17962887
Hi Sirdots
Any comments does it worked???
0
 

Author Comment

by:Sirdots
ID: 17967212
Thanks Deepesh. I already added that. It is the special character that XML will not take that was the problem.
0
 
LVL 35

Accepted Solution

by:
YZlat earned 500 total points
ID: 17967268
did you try this?

<add key ="result" value ="AP26E&#62;M*,PL;G-{#9^{}c8AKM&#60;,PL0i[(Di]OQ{#kKG3aRT0COG+UT{&_#%NA=@Mv" />
0
 
LVL 5

Expert Comment

by:DEEPESH
ID: 17970930
Amazing Sirdots
<add key ="result" value ="AP26E>M*,PL;G-{#9^{}c8AKM<,PL0i[(Di]OQ{#kKG3aRT0COG+UT{&_#%NA=@Mv" />

This string is working fine at my end
0
 
LVL 35

Expert Comment

by:YZlat
ID: 18220671
It seems to me that I gave him the solution. I had the same problem in the past and it worked for me
0

Featured Post

ScreenConnect 6.0 Free Trial

Want empowering updates? You're in the right place! Discover new features in ScreenConnect 6.0, based on partner feedback, to keep you business operating smoothly and optimally (the way it should be). Explore all of the extras and enhancements for yourself!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question