Solved

Reading the app.config file

Posted on 2006-11-14
18
960 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
  • 3
  • +2
18 Comments
 
LVL 143

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
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

739 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