Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 977
  • Last Modified:

Reading the app.config file

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
Sirdots
Asked:
Sirdots
  • 5
  • 4
  • 3
  • +2
1 Solution
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
if you remove the key "result" from the config file, does it still error out?

0
 
SirdotsAuthor Commented:
Yes. But I need the key "result" for something else. cant I have a lot of entries?
0
 
YZlatCommented:
replace all characters with hexadecimal values
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
SirdotsAuthor Commented:
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
 
YZlatCommented:
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
 
YZlatCommented:
but first try

<add key ="result" value ="AP26E&#62;M*,PL;G-{#9^{}c8AKM&#60;,PL0i[(Di]OQ{#kKG3aRT0COG+UT{&_#%NA=@Mv" />
0
 
appariCommented:
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
 
SirdotsAuthor Commented:
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
 
DEEPESHCommented:
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
 
DEEPESHCommented:
Hi Sirdots
Any comments does it worked???
0
 
SirdotsAuthor Commented:
Thanks Deepesh. I already added that. It is the special character that XML will not take that was the problem.
0
 
YZlatCommented:
did you try this?

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

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 5
  • 4
  • 3
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now