XML Config Transform not working for NLog on Linux target

Seems to be the same error as previously reported here:

and here:
https://help.octopus.com/t/problem-with-config-file-transformation/6688/3

Neither of these contain solutions that work.

We have Windows targets that this step works fine on.
When deploying to a Linux (Ubuntu 20.04) target we get the error xsi is an undeclared prefix

System.Xml.XmlException: 'xsi' is an undeclared prefix. Line 2, position 17. 
September 9th 2020 14:33:28
Error
   at System.Xml.XmlTextReaderImpl.Throw(Exception e) 
September 9th 2020 14:33:28
Error
   at System.Xml.XmlTextReaderImpl.LookupNamespace(NodeData node) 
September 9th 2020 14:33:28
Error
   at System.Xml.XmlTextReaderImpl.AttributeNamespaceLookup() 
September 9th 2020 14:33:28
Error
   at System.Xml.XmlTextReaderImpl.ParseAttributes() 
September 9th 2020 14:33:28
Error
   at System.Xml.XmlTextReaderImpl.ParseElement() 
September 9th 2020 14:33:28
Error
   at System.Xml.XmlTextReaderImpl.ParseDocumentContent() 
September 9th 2020 14:33:28
Error
   at System.Xml.XmlTextReaderImpl.Read() 
September 9th 2020 14:33:28
Error
   at Octopus.Web.XmlTransform.XmlAttributePreservationDict.EnumerateAttributes(String elementStartTag, Action`3 onAttributeSpotted) 
September 9th 2020 14:33:28
Error
   at Octopus.Web.XmlTransform.XmlAttributePreservationDict.ReadPreservationInfo(String elementStartTag) 
September 9th 2020 14:33:28
Error
   at Octopus.Web.XmlTransform.XmlAttributePreservationProvider.GetDictAtPosition(Int32 lineNumber, Int32 linePosition) 
September 9th 2020 14:33:28
Error
   at Octopus.Web.XmlTransform.XmlFileInfoDocument.XmlFileInfoElement..ctor(String prefix, String localName, String namespaceUri, XmlFileInfoDocument document) 
September 9th 2020 14:33:28
Error
   at Octopus.Web.XmlTransform.XmlFileInfoDocument.CreateElement(String prefix, String localName, String namespaceURI) 
September 9th 2020 14:33:28
Error
   at System.Xml.XmlLoader.LoadNode(Boolean skipOverWhitespace) 
September 9th 2020 14:33:28
Error
   at System.Xml.XmlLoader.LoadDocSequence(XmlDocument parentDoc) 
September 9th 2020 14:33:28
Error
   at System.Xml.XmlLoader.Load(XmlDocument doc, XmlReader reader, Boolean preserveWhitespace) 
September 9th 2020 14:33:28
Error
   at System.Xml.XmlDocument.Load(XmlReader reader) 
September 9th 2020 14:33:28
Error
   at Octopus.Web.XmlTransform.XmlFileInfoDocument.LoadFromTextReader(TextReader textReader) 
September 9th 2020 14:33:28
Error
   at Octopus.Web.XmlTransform.XmlFileInfoDocument.LoadFromFileName(String filename) 
September 9th 2020 14:33:28
Error
   at Octopus.Web.XmlTransform.XmlFileInfoDocument.Load(String filename) 
September 9th 2020 14:33:28
Error
   at Calamari.Common.Features.ConfigurationTransforms.ConfigurationTransformer.ApplyTransformation(String configFile, String transformFile, String destinationFile, IXmlTransformationLogger logger) in C:\buildAgent\work\e0cefbed4ad11812\source\Calamari.Common\Features\ConfigurationTransforms\ConfigurationTransformer.cs:line 85 
September 9th 2020 14:33:28
Error
   at Calamari.Common.Features.ConfigurationTransforms.ConfigurationTransformer.PerformTransform(String configFile, String transformFile, String destinationFile) in C:\buildAgent\work\e0cefbed4ad11812\source\Calamari.Common\Features\ConfigurationTransforms\ConfigurationTransformer.cs:line 34 
September 9th 2020 14:33:28
Error
Could not transform the file '/home/Octopus/Applications/.../3.66.0-fix-deployment-s0002/nlog.config' using the pattern 'Release'. 

As far as transformations go our nlog configs are not complicated

nlog.config

<nlog autoReload="true" 
      xmlns="http://www.nlog-project.org/schemas/NLog.xsd" 
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <targets>
        <target name="csv"
                xsi:type="File"
                ...>
            <layout xsi:type="CSVLayout">
...
            </layout>
        </target>
    </targets>

    <rules>
        <logger name="*" minlevel="Debug" writeTo="csv" />
    </rules>
</nlog>

nlog.Release.config

<nlog 
        xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
        xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
    <targets>
        <target name="csv" fileName="#{LogPath}" archiveFileName="#{LogArchivePath}" xdt:Transform="SetAttributes" xdt:Locator="Match(name)" />
    </targets>
    <rules>
        <logger name="*" minlevel="Info" xdt:Transform="SetAttributes" xdt:Locator="Match(name)" />
    </rules>
</nlog>

This does feel like an issue in the Octopus config transformation code, especially as the stacktrace shows it and it already works on Windows. Running this through online transformation checkers also shows no errors.

Hi @ops!

Thanks for reaching out, and sorry to hear that you’re having issues with your transform. I spun up a reproduction of this, and observed the same problem using your sample files when deploying to linux (after successfully deploying the same package to windows). I’ve created a github issue for this here: https://github.com/OctopusDeploy/Issues/issues/6569 - which you may want to subscribe to in order to stay abreast of updates related to this.

Feel free to reach out if you have any further questions.

1 Like

@Justin_Walsh you are a star.
Thanks for looking into this.
For now I have removed the namespaces to workaround the issue but I am not sure that is going to be correct going forward. Appreciate your help with this.

Mike

1 Like

Hi @ops,

This issue has been fixed in 2020.4 Octopus version.

Regards
John

1 Like

Thanks for the update and quick turnaround @John_Simons

1 Like