Solved

Reading the app.config file

Posted on 2006-11-14
18
951 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
 

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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

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…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

863 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now