XML Document Transforms (XDT) fail with InvalidDataException
mrward opened this issue · 4 comments
XDT supported was included in NuGet 2.6. Trying to install a NuGet package with a basic XDT on Linux using Mono 2.10.9 throws an InvalidDataException.
Template app.config.install.xdt
<?xml version="1.0"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<connectionStrings>
<add name="MyDB"
connectionString="value for the deployed Web.config file"
xdt:Transform="SetAttributes" xdt:Locator="Match(name)"/>
<add name="AWLT" connectionString="newstring"
providerName="newprovider"
xdt:Transform="Insert" />
</connectionStrings>
<system.web>
<customErrors defaultRedirect="GenericError.htm"
mode="RemoteOnly" xdt:Transform="Replace">
<error statusCode="500" redirect="InternalError.htm"/>
</customErrors>
</system.web>
</configuration>
Error on installing NuGet package
An error occurred while applying transformation to 'app.config' in project 'NuGetTest': Argument cannot be null.
Parameter name: key
System.IO.InvalidDataException: An error occurred while applying transformation to 'app.config' in project 'NuGetTest': Argument cannot be null.
Parameter name: key ---> Microsoft.Web.XmlTransform.XmlNodeException: Argument cannot be null.
Parameter name: key ---> System.ArgumentNullException: Argument cannot be null.
Parameter name: key
at System.Xml.NameTable.Add (System.String key) [0x000ae] in /home/abuild/rpmbuild/BUILD/mono-2.10.9/mcs/class/System.XML/System.Xml/NameTable.cs:111
at System.Xml.XmlAttribute.set_Prefix (System.String value) [0x0004b] in /home/abuild/rpmbuild/BUILD/mono-2.10.9/mcs/class/System.XML/System.Xml/XmlAttribute.cs:210
at Microsoft.Web.XmlTransform.XmlElementContext.ScrubTransformAttributesAndNamespaces (System.Xml.XmlNode node)
at Microsoft.Web.XmlTransform.XmlElementContext.CreateCloneInTargetDocument (System.Xml.XmlNode sourceNode)
at Microsoft.Web.XmlTransform.XmlElementContext.get_TransformNode ()
at Microsoft.Web.XmlTransform.Transform.get_TransformNode ()
at Microsoft.Web.XmlTransform.Transform.ApplyOnAllTargetNodes ()
at Microsoft.Web.XmlTransform.Transform.Execute (Microsoft.Web.XmlTransform.XmlElementContext context, System.String argumentString)
--- End of inner exception stack trace ---
at Microsoft.Web.XmlTransform.XmlTransformationLogger.LogErrorFromException (System.Exception ex)
at Microsoft.Web.XmlTransform.Transform.Execute (Microsoft.Web.XmlTransform.XmlElementContext context, System.String argumentString)
at Microsoft.Web.XmlTransform.XmlTransformation.HandleElement (Microsoft.Web.XmlTransform.XmlElementContext context)
--- End of inner exception stack trace ---
at NuGet.XdtTransformer.PerformXdtTransform (IPackageFile file, System.String targetPath, IProjectSystem projectSystem)
at NuGet.XdtTransformer.TransformFile (IPackageFile file, System.String targetPath, IProjectSystem projectSystem)
at NuGet.ProjectSystemExtensions.AddFiles (IProjectSystem project, IEnumerable1 files, IDictionary
2 fileTransformers)
at NuGet.ProjectManager.ExtractPackageFilesToProject (IPackage package)
at NuGet.ProjectManager.AddPackageReferenceToProject (IPackage package)
at NuGet.ProjectManager.Execute (NuGet.PackageOperation operation)
at NuGet.ProjectManager.Execute (IPackage package, IPackageOperationResolver resolver)
at NuGet.ProjectManager.AddPackageReference (IPackage package, Boolean ignoreDependencies, Boolean allowPrereleaseVersions)
at NuGet.ProjectManager.AddPackageReference (System.String packageId, NuGet.SemanticVersion version, Boolean ignoreDependencies, Boolean allowPrereleaseVersions)
at ICSharpCode.PackageManagement.SharpDevelopPackageManager.AddPackageReference (IPackage package, Boolean ignoreDependencies, Boolean allowPrereleaseVersions)
at ICSharpCode.PackageManagement.SharpDevelopPackageManager.InstallPackage (IPackage package, ICSharpCode.PackageManagement.InstallPackageAction installAction)
at ICSharpCode.PackageManagement.PackageManagementProject.InstallPackage (IPackage package, ICSharpCode.PackageManagement.InstallPackageAction installAction)
at ICSharpCode.PackageManagement.InstallPackageAction.ExecuteCore ()
at ICSharpCode.PackageManagement.ProcessPackageAction.Execute ()
at ICSharpCode.PackageManagement.PackageActionRunner.Run (IPackageAction action)
at ICSharpCode.PackageManagement.PackageViewModel.InstallPackage (IEnumerable`1 packageOperations)
at ICSharpCode.PackageManagement.PackageViewModel.InstallPackage ()
at ICSharpCode.PackageManagement.PackageViewModel.TryInstallingPackage ()
Fixed in 597e42a
Using a custom build of the Microsoft.Web.XmlTransform assembly that sets the prefix on XmlAttributes to an empty string instead of null. Setting the prefix to null causes Mono to throw an ArgumentNullException.
Using a custom build of the Apache 2.0 licensed XDT source code from codeplex should get around the licensing restriction on the official Microsoft.Web.XmlTransform assembly that prevents distribution on non-Windows platforms.
Sorry for replying to this old post, but could you please elaborate on what you've changed exactly in your custom build of the Microsoft.Web.XmlTransform assembly? I'm having the same issue with our custom xbuild server and TransformXml build tasks.
The source code for the change is available on my fork of XDT.
The actual commit with the change is: mrward/xdt@488cc75
Awesome! Thanks for your reply! 👍