Azure-pipelines-tasks: ctt.exe Fails with NullReference exception when using `RemoveAttributes`

Created on 7 Mar 2018  路  5Comments  路  Source: microsoft/azure-pipelines-tasks

Troubleshooting

Checkout how to troubleshoot failures and collect debug logs: https://docs.microsoft.com/en-us/vsts/build-release/actions/troubleshooting

Steps taken

Success

  • Downloaded ctt

    • Ran ctt from commandline successfully for Web.config & Web.\

Failure

  • Added the following to existing working release (Remaining config trimmed for brevity):
    <configuration>
      <system.web>
        <compilation xdt:Transform="RemoveAttributes(debug)" />
      </system.web>
    </configuration>
  • Release breaks at Transform step with the following error message:
[command]D:\a\_tasks\AzureRmWebAppDeployment_497d490f-eea7-4f2b-ab94-48d9c1acdcb1\3.3.41\ctt\ctt.exe s:D:\a\r1\a\temp_web_package_5373537669592361\Content\D_C\a\1\s\Project\obj\PROD\Package\PackageTmp\Web.config t:D:\a\r1\a\temp_web_package_5373537669592361\Content\D_C\a\1\s\Project\obj\PROD\Package\PackageTmp\Web.DEV.config d:D:\a\r1\a\temp_web_package_5373537669592361\Content\D_C\a\1\s\Project\obj\PROD\Package\PackageTmp\Web.config pw i
2018-03-06T22:23:24.7532152Z System.NullReferenceException: Object reference not set to an instance of an object.
2018-03-06T22:23:24.7532569Z    at Microsoft.Web.XmlTransform.XmlTransformationLogger.ConvertUriToFileName(XmlDocument xmlDocument)
2018-03-06T22:23:24.7532961Z    at Microsoft.Web.XmlTransform.XmlTransformationLogger.LogWarning(XmlNode referenceNode, String message, Object[] messageArgs)
2018-03-06T22:23:24.7533300Z    at Microsoft.Web.XmlTransform.Transform.ApplyOnAllTargetNodes()

Environment

  • Server - VSTS

    • If using VSTS, provide the account name, team project name, build definition name/build number:
  • Agent - Hosted or Private:

    • Both failed

    • If using Hosted agent, provide agent queue name: Hosted VS2017

    • If using private agent, provide the OS of the machine running the agent and the agent version: Windows Server 2016 (I believe.)

Issue Description

  • When using the Azure App Service Deploy v3 with XML transformation checked, release fails with the below error message if xdt:Transform=RemoveAttributes(debug) is present on an element.

    • Switching to xdt:Transform=SetAttributes(debug) worked fine.

    • Found blog post & MSDN help indicating similar issues

Error logs

[command]D:\a\_tasks\AzureRmWebAppDeployment_497d490f-eea7-4f2b-ab94-48d9c1acdcb1\3.3.41\ctt\ctt.exe s:D:\a\r1\a\temp_web_package_5373537669592361\Content\D_C\a\1\s\Project\obj\PROD\Package\PackageTmp\Web.config t:D:\a\r1\a\temp_web_package_5373537669592361\Content\D_C\a\1\s\Project\obj\PROD\Package\PackageTmp\Web.DEV.config d:D:\a\r1\a\temp_web_package_5373537669592361\Content\D_C\a\1\s\Project\obj\PROD\Package\PackageTmp\Web.config pw i
2018-03-06T22:23:24.7532152Z System.NullReferenceException: Object reference not set to an instance of an object.
2018-03-06T22:23:24.7532569Z    at Microsoft.Web.XmlTransform.XmlTransformationLogger.ConvertUriToFileName(XmlDocument xmlDocument)
2018-03-06T22:23:24.7532961Z    at Microsoft.Web.XmlTransform.XmlTransformationLogger.LogWarning(XmlNode referenceNode, String message, Object[] messageArgs)
2018-03-06T22:23:24.7533300Z    at Microsoft.Web.XmlTransform.Transform.ApplyOnAllTargetNodes()
Release

Most helpful comment

@brianvanderlugt This error would generally pop up if you are trying to remove an attribute which does not exist in the Web.config file. Please check if the "debug" attribute is present in the tag where you are applying the transform. It is also possible that you have a Web.Release.config file where xdt:Transform=RemoveAttributes(debug) is already present. When the release runs, it applies transformations in the order Web.Release.config followed by other Web.*.config files.

All 5 comments

@brianvanderlugt This error would generally pop up if you are trying to remove an attribute which does not exist in the Web.config file. Please check if the "debug" attribute is present in the tag where you are applying the transform. It is also possible that you have a Web.Release.config file where xdt:Transform=RemoveAttributes(debug) is already present. When the release runs, it applies transformations in the order Web.Release.config followed by other Web.*.config files.

@asranja Thanks for the reply! Long story short, it was user error accidentally applying the transform twice: once at build and then again at release. I discovered my issue after trying to confirm that the attribute was present by the time the release transform was occurring. I had renamed the default Release configuration to PROD and was using that in my build configuration. This was packaged for WebDeploy and I hadn't inspected inside the zip file. I made the assumption the Web.Config was the same from source, but it had the transform applied from PROD when zipped up at build. Therefore the attribute was gone and I was getting the error when removing it a second time.

Exactly the same story as with @brianvanderlugt. Thank you for opening the issue. Tracked down 2nd transformation. I guess CTT should not crash if it can't transform.

OMG, this was what was causing it!

It was my first pipeline so I really wasn't sure where to start.

That null ref exception is followed by the rest of the transform actions appearing as if they work fine so it looks like it's just caught it and continued on.
It even reports: Done executing RemoveAttributes

Please can you re-open this and maybe do a null check on the attribute before attempting to remove it?

Pretty sure that most people wouldn't expect an error if RemoveAttribute is executed for an attribute that does not exist.
In my particular case it was caused because the Release transform removed the debug attribute at build and then the environment specific transform at release / deploy was also removing it.

That feels like it would be a very common scenario.

I've attached the log so you can see how confusing it is.

RemoveAttributes_appears_to_work_but_errors.txt

Hiya,

I did a bit of digging and the ctt.exe code is still on codeplex https://ctt.codeplex.com
It references .net xdt which is where the null ref exception comes from and what's causing the inconsistent error.

Fixed the error and submitted a PR for it so hopefully it'll get merged and you can just update the nuget ref inside ctt.exe

It's just a typo, PR here - https://github.com/aspnet/xdt/pull/216

Actually, is anyone maintaining ctt.exe?

Was this page helpful?
0 / 5 - 0 ratings