The xml was improperly formatted.

Ask questions about creating Graphical User Interfaces (GUI) in PowerShell and using WinForms controls.
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
User avatar
phhebert
Posts: 15
Joined: Mon Sep 26, 2016 8:24 am

The xml was improperly formatted.

Post by phhebert » Fri Sep 28, 2018 5:35 am

Hi everyone,

I have a Windows form with a textbox in it. When I use debugger on KeyPress Event after pressing backspace key and look for the $_.KeyChar property, it shows me "The XML was improperly formatted. Please escape if it necessary". What's going on here?

User avatar
jvierra
Posts: 13571
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: The xml was improperly formatted.

Post by jvierra » Fri Sep 28, 2018 6:00 am

Where are you using XML in your code?

Can you post the exact error text or an image of the error message?

User avatar
davidc
Posts: 5883
Joined: Thu Aug 18, 2011 4:56 am

Re: The xml was improperly formatted.

Post by davidc » Fri Sep 28, 2018 6:46 am

Is this message appearing when you hover over the variable?

What value do you see in the Variables panel (or the Watch panel if you right-click on the property and use "Add to Watch").
David
SAPIEN Technologies, Inc.

User avatar
phhebert
Posts: 15
Joined: Mon Sep 26, 2016 8:24 am

Re: The xml was improperly formatted.

Post by phhebert » Fri Sep 28, 2018 7:14 am

I don't use any XML in this script.

The message appears when I hover the mouse over the $_ variable. There is no value in the watch panel when I type $_.KeyChar.

User avatar
phhebert
Posts: 15
Joined: Mon Sep 26, 2016 8:24 am

Re: The xml was improperly formatted.

Post by phhebert » Fri Sep 28, 2018 7:22 am

See the attachment.

Thanks
Attachments
1.png
1.png (57.54 KiB) Viewed 544 times

User avatar
jvierra
Posts: 13571
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: The xml was improperly formatted.

Post by jvierra » Fri Sep 28, 2018 7:50 am

Thanks for the image. I will let David respond as this is likely an issue with PSS or, possibly, your PSF file is corrupted which can cause all manner of odd behaviors. David and Sapien would be able to ascertain this.

User avatar
jvierra
Posts: 13571
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: The xml was improperly formatted.

Post by jvierra » Fri Sep 28, 2018 8:05 am

I just copied your code and can reproduce the issue. I believe it can be ignored as it it just trying to show the tooltip text for $_.KeyChar which apparently cannot be decoded. This only happens if we hit the BackSpace key.

Here is the simplest form that reproduces the issue.

Code: Select all

$form1_Load={
}
$textbox1_KeyPress=[System.Windows.Forms.KeyPressEventHandler]{
#Event Argument: $_ = [System.Windows.Forms.KeyPressEventArgs]
       Write-Host $_.KeyChar
}
Attached is a simple form with one textbox that shows your issue. I suspect the wrong internal message is being extracted or possible the tooltip generator has a simple bug. I think we can safely ignore this for now.
Attachments
Test-XMLIssue.psf
(17.49 KiB) Downloaded 13 times

User avatar
davidc
Posts: 5883
Joined: Thu Aug 18, 2011 4:56 am

Re: The xml was improperly formatted.

Post by davidc » Fri Sep 28, 2018 8:09 am

The backspace doesn't produce a printable character. We will look into this and see what we can do.
David
SAPIEN Technologies, Inc.

User avatar
phhebert
Posts: 15
Joined: Mon Sep 26, 2016 8:24 am

Re: The xml was improperly formatted.

Post by phhebert » Fri Sep 28, 2018 8:12 am

Ok thanks for confirming that it's just a simple bug I can ignore.

User avatar
jvierra
Posts: 13571
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: The xml was improperly formatted.

Post by jvierra » Fri Sep 28, 2018 8:15 am

davidc wrote:
Fri Sep 28, 2018 8:09 am
The backspace doesn't produce a printable character. We will look into this and see what we can do.
That would explain the XML error as most unprintable characters haved to be escaped in XML so the fix should be trivial except for the regression testing.

It is clearly not anything that affects the script or the debugging other than a vague and uninformative message.

Locked