error storing < and > characters in app.config file in C#

11,657

Solution 1

Just change the < and > to &lt; and &gt;.

Solution 2

If you indeed need to put that query in the app.config, you can put it inside a CDATA section or you can escape those characters with &lt; and &gt;

Solution 3

First, if you're storing SQL in the app.config you're probably doing something wrong. As @ChrisBint said, you should probably put this in an embedded resource file instead.

That being said, you should be able to correct the problem by replacing any special characters with a proper entity:

<  ... &lt;
>  ... &gt;

"  ... &quot;

Solution 4

Store the SQL in a resource file rather than the app.config.

Solution 5

(greater-than character) use "&gt"

Must be used for an attribute value, but > is acceptable as the content of an element as long as < does not precede it.

< (less-than character) - use "&lt"

Must be used for an attribute value, but < is acceptable as the content of an element as long as > does not follow it.

source - http://msdn.microsoft.com/en-us/library/ms748250.aspx

Share:
11,657
dnyan86
Author by

dnyan86

Updated on June 25, 2022

Comments

  • dnyan86
    dnyan86 almost 2 years

    I want to store a sql query in app.config file which has < and > characters but file shows error 'expecting >' , have you come across this problem ?