Deployment–Why does PDT think my Variable.xml is invalid?

Deployment–Why does PDT think my Variable.xml is invalid?

  • Comments 1
  • Likes

One question that I hear often on PDT is this – why does PDT think my Variable.xml is invalid?

When you run any of the PDT scripts – Downloader.ps1, VMCreator.ps1, or Installer.ps1 – the script reads both Workflow.xml and Variable.xml.  If either one of them is invalid, it just spits out a red error message telling you that, and stops.  Since you likely haven’t changed Workflow.xml (if you have… we should talk) it is usually Variable.xml that is invalid.

The error doesn’t mean you got something wrong in the Variable.xml, such as missing a dependent role or a variable – those type of errors are handled by pre-installation validation.  The error means that the file is not a valid XML file – which means you probably missed a < or a / somewhere.  These types of errors can be hard to find… unless you know the trick.

Now, what I’ve done in the past is have whoever asked the question send me a copy of their Variable.xml file, and within about a minute I tell them where the error is, usually to their amazement and disbelief.  No, I do not have super-senses when it comes to looking at XML files…

The way to find the error is this – just attempt to load the file manually in PowerShell, and the PowerShell error will tell you which line in the XML file the error is on.  The way you do this is:

$Variable = [XML] (Get-Content .\Variable.xml)

You’ll get an error along the lines of…

Cannot convert value "System.Object[]" to type "System.Xml.XmlDocument". Error: "'<' is an unexpected token. The
expected token is '>'. Line 19, position 5."
At line:1 char:1
+ $Variable = [XML] (Get-Content .\Variable.xml)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (:) [], RuntimeException
    + FullyQualifiedErrorId : InvalidCastToXmlDocument

…so now you know the error is on line 19, and can easily fix it.

Isn’t that easy?

Your comment has been posted.   Close
Thank you, your comment requires moderation so it may take a while to appear.   Close
Leave a Comment
  • Thanks for the blog! Because of its flexibility (and studying your PDT), I have started to use XML more and more to drive configurations. But missing characters in XML files were driving me nuts. I had tried a number of different editors that attempted to show inconsistencies, but none work as quickly and as easily as this.