Configure XML configuration transforms running twice

The version of my Octopus Server : v4.1.9
The version of my Calamari: v4.1.7
Logs do not show duplicate execution.
2 Roles associated with same server; however, the step is associated with only AppServer role.
2 Octopus Deploy Tentacles running on same server; however, AppServer role is only associated with a single tentacle instance. I also stopped the non affecting tentacle and problem continues to occur.

It appears that Configure XML configuration transforms is running twice for the same file.

While running xml transforms on xml like below (condensed):

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <log4net>
	<root>
	  <level value="DEBUG" />
	  <appender-ref ref="ODS" />
	  <appender-ref ref="File" />
	  <appender-ref ref="Console" />
	  <!--<appender-ref ref="SMTP" />-->
	</root>
  </log4net>
</configuration>

Getting error:
No element in the source document matches ‘/configuration/log4net/root/appender-ref[@ref=‘Console’]’

Added
Octopus.Action.Package.TreatConfigTransformationWarningsAsErrors = False

Now the transform (condensed):

<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
  <log4net>
	<root>
	  <appender-ref xdt:Locator="Condition(@ref='Console')" xdt:Transform="Remove" />
	  <appender-ref ref="SMTP" xdt:Transform="Insert" />
	</root>
  </log4net>
</configuration>

performs the “Remove” transform, then logs the warning:

    "No element in the source document matches '/configuration/log4net/root/appender-ref[@ref='Console']' "

and inserts 2 entries for: appender-ref ref=“SMTP” as seen below:

<root>
  <level value="DEBUG" />
  <appender-ref ref="ODS" />
  <appender-ref ref="File" />
  <!--<appender-ref ref="SMTP" />-->
  <appender-ref ref="SMTP"/>
  <appender-ref ref="SMTP"/>
</root>

and as can be seen the ‘Console’ setting is removed.

This is a multi-step deployment with other steps doing almost the exact same thing for other services with slight changes in the step configuration. These other steps are also old steps that were created when the server was on version 2.6. This new step (created on v4.1.9) insists on running the Remove and Insert transforms twice or at least it appears to be.

Also unchecked “Run default Xml Transformations” and replaced with explicit transformation statement:
Ai.NotificationService.exe.Release.config => Ai.NotificationService.exe.config
with the same results.

Updated transform file to UTF-8 instead of Western European (Windows) which shouldn’t matter since other working transform files are Western Europen (Windows).

Also created a brand new project with just this one deployment step with same results.

Could not reproduce the duplication or error running the following code :

        using (XmlTransformableDocument document = new XmlTransformableDocument())
        using (XmlTransformation transformation = new XmlTransformation(transformFilePath))
        {
            document.PreserveWhitespace = true;
            document.Load(sourceFilePath);

            var success = transformation.Apply(document);
            if (!success)
            {
                string message = string.Format(
                    "There was an unknown error trying while trying to apply the transform. Source file='{0}',Transform='{1}', Destination='{2}'",
                    sourceFilePath, transformFilePath, destinationFilePath);
                throw new Exception(message);
            }

            document.Save(destinationFilePath);
        }

Fixed… It was the encoding of the App.config file.

Here’s another one with the same issue:

https://help.octopusdeploy.com/discussions/problems/52743-transformation-getting-applied-twice

The App.config file had an encoding of “Unicode (UTF-8) with signature”. I updated the App.config file to “Unicode (UTF-8) without signature”"

Hi Wally,

Thanks for getting in touch! And thank you for the detailed outline of your problem. I’m glad to hear that you resolved your issue. I will look into whether we should perhaps update our documentation around this to help others who may run into this same problem.

Please let me know if you have any further questions or thoughts here.

Best regards,
Daniel