Transform of a xdt:Replace on a root node throws an exception on 3.0

After upgrading to 3.0 our deployment was failing on an xdt transform. The file in question was performing a xdt:Replace on a file containing a single root node. The Transform is a “Replace”.

For example the entire file content of the transform would be

I can workaround the problem by setting the Transform to SetAttributes. This previously worked on 2.6.


Should have been

<MySettings xmlns:xdt="" xdt:Transform="Replace" 
enableSelfService="True" />

Hi Peter,
Just to confirm a few things, what specific version are you running (Tentacle & Server) and what are the details of the error in question. Scheenshots or logs would be great to get to the bottom of this.

Hi Robert,
The version is 3.1.4 both Tentacle and Server.

The stack trace is:

System.InvalidOperationException : Cannot insert the node in the specified location.
   at System.Xml.XmlNode.InsertBefore(XmlNode newChild, XmlNode refChild)
   at Microsoft.Web.XmlTransform.XmlFormatter.EnsureNodeIndent(XmlNode node, Boolean indentBeforeEnd)
   at Microsoft.Web.XmlTransform.XmlFormatter.HandleStartElement(XmlNode node)
   at Microsoft.Web.XmlTransform.XmlFormatter.HandleElement(XmlNode node)
   at Microsoft.Web.XmlTransform.XmlFormatter.FormatLoop(XmlNode parentNode)
   at Microsoft.Web.XmlTransform.XmlFormatter.Format(XmlDocument document)
   at Microsoft.Web.XmlTransform.XmlFileInfoDocument.Save(String filename)
   at Calamari.Integration.ConfigurationTransforms.ConfigurationTransformer.ApplyTransformation(String configFile, String transformFile, String destinationFile, IXmlTransformationLogger logger) in ConfigurationTransformer.cs: line 75
   at Calamari.Integration.ConfigurationTransforms.ConfigurationTransformer.PerformTransform(String configFile, String transformFile, String destinationFile) in ConfigurationTransformer.cs: line 36

I’ve created a repro with a test here:

Hi Peter,
I have just reproduced your replacement in Calamari and found that if <?xml version="1.0"?> is missing then I get the InvalidOperationException. Could you try add this xml declaration and try again.

Hi Robert,
Yes, this has the same effect as changing to a SetAttributes transform.

Any idea why this behaviour changed from 2.6 to 3.1.4?

Hi Peter,
We made a few changes to the deployment engine going from 2.6 to 3.0 and its possible that something fundamental to the Transformations might have been updated. As you can see in the source code we are using the in-built Microsoft.Web.XmlTransform.XmlTransformation class to do the transform it should be compliant with expected behavior.
Hope you can get back to kicking out deployments again.


Just to report that in 3.2.23 at least this issue still exists.
But the workaround of adding <?xml version="1.0"?> helped.