22

I have the following appSettings section

<appSettings>
  <add key="Foo" value="http://foo.bar.com/?app=xxx&FormName=yyy" />
</appSettings>

But the IDE is giving me two errors:

  1. Error 25 Entity 'FormName' not defined.
  2. Error 26 Expecting ';'.

It seems the & is causing a problem. I'd like to not have to splt the values up into seperate keys. Is there an elegant way around this issue?

live-love
  • 41,600
  • 19
  • 198
  • 177
WhiskerBiscuit
  • 4,587
  • 7
  • 51
  • 91
  • 3
    You just need to remember that a `.config` file is XML and all XML rules still apply... – Oded Jun 06 '12 at 17:08
  • possible duplicate of [How can I add an ampersand for a value in a ASP.net/C# app config file value](http://stackoverflow.com/questions/376135/how-can-i-add-an-ampersand-for-a-value-in-a-asp-net-c-app-config-file-value) – JohnnyHK Nov 05 '14 at 21:03

2 Answers2

51

You just need to use XML encoding here I believe - so & becomes &amp;

RobV
  • 26,967
  • 10
  • 74
  • 115
11
Try &amp;

<appSettings>
  <add key="Foo" value="http://foo.bar.com/?app=xxx&amp;FormName=yyy" />
</appSettings>
Adil
  • 143,427
  • 25
  • 201
  • 198