vmware-archive / powernsx

PowerShell module that abstracts the VMware NSX-v API to a set of easily used PowerShell functions
173 stars 90 forks source link

strange error with get-nsxedge #649

Closed MartinEtcheverry closed 3 years ago

MartinEtcheverry commented 3 years ago

when i run a simple get-nsxedge i get this error:

$edges = get-nsxedge MethodInvocationException: C:\Users\someuser\Documents\PowerShell\Modules\PowerNSX\3.0.1174\PowerNSX.psm1:3615 Line | 3615 | $_xml.WriteContentTo($XmlWriter) | ~~~~~~~~ | Exception calling "WriteContentTo" with "1" argument(s): "'☺', hexadecimal value 0x01, is an invalid character." MethodInvocationException: C:\Users\someuser\Documents\PowerShell\Modules\PowerNSX\3.0.1174\PowerNSX.psm1:3615 Line | 3615 | $_xml.WriteContentTo($XmlWriter) | ~~~~~~~~ | Exception calling "WriteContentTo" with "1" argument(s): "'♣', hexadecimal value 0x05, is an invalid character."

Any hint , anybody?

dcoghlan commented 3 years ago

You have 2 non printing ASCII characters (technically they are ASCII control codes SOH and ENQ) somewhere in your configuration. Typically this will be in the name, description or any other field that a user has been able to type into. Where I have seen this type of stuff before is when people copy and paste text from another document into the fields.

Tracking down the field where this is present will be a bit more tricky. It would often mean taking the raw API output (using something like Postman) and putting it into some sort of text editor that will show you non-ascii printing characters.

The reason PowerNSX is throwing an error is due to the fact that as part of the Invoke-NsxRestMethod, we pass the XML response through Format-XML to write the XML response into the debug logs in a format that is easy to read. Format-XML uses XmlWriterwhich has a data conformance setting for CheckCharacters which defaults to true. This data conformance check validates that all characters are within the legal range for a XML document as defined by the W3C.

As a workaround, you could try the following steps to see if it resolves your issue

MartinEtcheverry commented 3 years ago

well , i made the modification and seems work fine!