Solved

Reading the app.config file

Posted on 2006-11-14
18
942 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]
Comment Utility
if you remove the key "result" from the config file, does it still error out?

0
 

Author Comment

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

Expert Comment

by:YZlat
Comment Utility
replace all characters with hexadecimal values
0
 

Author Comment

by:Sirdots
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 

Author Comment

by:Sirdots
Comment Utility
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
Comment Utility
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
Comment Utility
Hi Sirdots
Any comments does it worked???
0
 

Author Comment

by:Sirdots
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

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…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

772 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

12 Experts available now in Live!

Get 1:1 Help Now