25

I get the following error while transforming a web.config file in TeamCity. It happens on the element, <applicationSettings xdt:Transform="Replace">.

No element in the source document matches '/configuration/applicationSettings'

The source file has this setting. Any idea how to solve this?

Anthony Mastrean
  • 20,318
  • 20
  • 92
  • 173
sam
  • 4,388
  • 10
  • 56
  • 109

2 Answers2

29

I had to remove the namespace attribute from the configuration node. There is some conflict in the declared schema and the elements I was using.

xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0"
Anthony Mastrean
  • 20,318
  • 20
  • 92
  • 173
sam
  • 4,388
  • 10
  • 56
  • 109
  • 3
    I was looking for a solution for this problem, and this is the only answer on the web that worked for me, thanks! – saman0suke Sep 29 '14 at 04:06
18

I would like to give a more detailed answer for others here.

In Visual Studio 2010 the web.config transform engine didn't respect xmlns declarations. Because of that if your source web.config had an xmlns declaration, and if you created a transform then the transformation would not work. This is because when we perform the XPath to identify the source which should be replaced we cannot find the value. In order to work around this you should remove the xmlns declaration on the source web.config as well as the transform.

With that being said, in Visual Studio 2010 SP1 we fixed the namespace bug. So your source web.config as well as your transformation must agree on the xmlns, if one has it the other must have it as well.

I suspect that you are using the pre-SP1 bits, but not sure. In order to ensure that the behavior doesn't change if you upgrade to SP1 I recommend you remove xmlns declaration from your source web.config as well as your transforms. The xmlns is not needed in the web.config file so it is safe to remove it.

Sayed Ibrahim Hashimi
  • 42,483
  • 14
  • 139
  • 172
  • am I right that its possible to workaround this bug with named namespace in transformation file, matched corresponding xmlns from transformed file ? Its not good to remove namespaces from xml - then it will be completely different xml from the point of xml processor... – Alexey Shcherbak Mar 15 '12 at 09:19
  • You don't need named ns elements, you can make it work with the default xmlns but they have to be on both source as well as transform. With that being said. For web.config there is no difference if there is an xmlns or not. It's recommend to not have it (also explains why there is no xmlns on web.config when you create a new project in VS). – Sayed Ibrahim Hashimi Mar 16 '12 at 05:20
  • we are using transformations not only for web.config kind of xml =\ – Alexey Shcherbak Mar 16 '12 at 15:58
  • They should work as long as your namespace declarations match for both document/transform. – Sayed Ibrahim Hashimi Mar 16 '12 at 16:41
  • Due to some yet unknown curcumstances I got following error message "Namespace Manager or XsltContext needed. This query has a prefix, variable, or user-defined function." when I trying to prefix all elements in transformation. I dont sure that we could easily deploy SP1 on that build machine atm. Any hints to workaround this ? – Alexey Shcherbak Mar 19 '12 at 12:24
  • "They should work as long as your namespace declarations match for both document/transform" It doesn't work - it's ridiculous. I have the same xmlns= value in both the base config and the transformer config - it doesn't transform because it can't find a matching node in the base config. The XmlTransformation class doesn't seem to support namespaces. This blows our use of Quartz.Net out of the water because Quartz requires an xmlns= value set in the file. How is it possible in this day and age that xml namespaces aren't supported? – znelson Aug 30 '12 at 20:38
  • I'm using Visual Studio 2017 and still have the exact same problem for '/configuration/system.webServer/rewrite'. – Jonathan Wood Jun 05 '17 at 18:38