Transforming the root node of a config file that contains a namespace fails with this error:
Could not write Destination file: Object reference not set to an instance of an object.
This transform will cause the exception to be thrown:
I think this is related to the Microsoft.Web.Xdt package. The transform executes successfully, but the exception is thrown on document.Save(destination)
public class Transformer : ITransformer {
public void Transform(string source, string transform, string destination) {
if (string.IsNullOrWhiteSpace(source)) { throw new ArgumentNullException("source"); }
if (string.IsNullOrWhiteSpace(transform)) { throw new ArgumentNullException("transform"); }
if (string.IsNullOrWhiteSpace(destination)) { throw new ArgumentNullException("destination"); }
if (!File.Exists(source)) {
throw new FileNotFoundException("File to transform not found", source);
}
if (!File.Exists(transform)) {
throw new FileNotFoundException("Transform file not found", transform);
}
using (XmlTransformableDocument document = new XmlTransformableDocument())
using (XmlTransformation transformation = new XmlTransformation(transform)) {
document.PreserveWhitespace = true;
document.Load(source);
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}'",
source,transform,destination);
throw new TransformFailedException(message);
}
// Error occurs here
// Could not write Destination file: Object reference not set to an instance of an object.
document.Save(destination);
}
}
I downloaded the SlowCheetah project and updated the Microsoft.Web.Xdt nuget package to the latest version. That stopped the error from happening.
I was going to try to fix the project and submit a pull request, but I am not familiar with Nuget package projects or Visual Studio extension projects. SlowCheetah.Xdt.dll has a dependency on an older version of Microsoft.Web.XmlTransform.
I have tried this with the new version (2.5.48) and root node transforms are working.
If you are still experiencing this after updating, reopen the issue and add steps to reproduce this from a new project.
Transforming the root node of a config file that contains a namespace fails with this error: Could not write Destination file: Object reference not set to an instance of an object.
This transform will cause the exception to be thrown:
I think this is related to the Microsoft.Web.Xdt package. The transform executes successfully, but the exception is thrown on document.Save(destination)
I downloaded the SlowCheetah project and updated the Microsoft.Web.Xdt nuget package to the latest version. That stopped the error from happening.
I was going to try to fix the project and submit a pull request, but I am not familiar with Nuget package projects or Visual Studio extension projects. SlowCheetah.Xdt.dll has a dependency on an older version of Microsoft.Web.XmlTransform.