0

This setting is not allowed in App.Config due to the error The element app settings has invalid element 'BscSerialNumber'. List of possible elements expected 'add,remove,clear'

  <add key="PreValue" value="<BscSerialNumber>"/>

The value <BscSerialNumber> is an actual string that i want in my setting.

user1438082
  • 2,740
  • 10
  • 48
  • 82
  • 1
    Replace with special sequence like here. [link](https://stackoverflow.com/questions/14607920/the-character-breaks-passwords-that-are-stored-in-the-web-config) See Kelsey's answer. – hastrb Aug 31 '17 at 12:44
  • 1
    [A pretty good list can be found here](https://stackoverflow.com/a/1091953/2099119) – waka Aug 31 '17 at 12:48

1 Answers1

3

You need to escape the angle-brackets. Use &lt; instead of < and &gt; instead of >.

The appsetting entry should end up looking like this:

<add key="PreValue" value="&lt;BscSerialNumber&gt;"/>

When you read the setting in code, it will contain the string, including the angle-brackets:

enter image description here

Lars Kristensen
  • 1,410
  • 19
  • 29
  • 2
    Or as well get rid of them. I assume whatever value goes there, will always have the form "" ... So it can be surrounded by "<>" at the client's side with less headaches. – Fildor Aug 31 '17 at 12:47
  • 1
    @Fildor We don't know if OP can make changes to the client that reads the values - but it definitely doesn't hurt to know how to escape characters in XML. – Lars Kristensen Aug 31 '17 at 12:55
  • 1
    I agree. It's just another option. – Fildor Aug 31 '17 at 12:56