Powershell: WinForms behavior differs in PS7 Preview 4

Created on 22 Oct 2019  路  17Comments  路  Source: PowerShell/PowerShell

Product Issue

_>> Platform: V7-preview 64Bit (STA) (Forced)

Exception setting "Location": "Cannot convert the "0, 24" value of type "System.String" to type "System.Drawing.Point"."
At C:\temp\MainForm.Run.ps1:413 char:2

  • $datagridview1.Location = '0, 24'
  • ~~~~~~~~~

All properties that accept point objects can be assigned with strings like "10,10" and the property assignment is correctly converted by PowerShell V2 thru V5.1 - PS 7 does not handle this correctly. There are millions of lines of PS code that uses this so it needs to be addressed.

Issue-Question Resolution-Duplicate

Most helpful comment

Ok, let's tracking in #9863

All 17 comments

I can not repo on PowerShell

@jvierrajrv Please move the issue to https://github.com/PowerShell/GraphicalTools

/cc @TylerLeonhardt For information

GitHub
A module that mixes PowerShell and GUIs! - built on Avalonia - PowerShell/GraphicalTools

In any version of PowerShell 5.1 or earlier paste the following code:

Add-Type -AssemblyName System.Windows.Forms
$control = [System.Windows.Forms.Textbox]::New()
$control.Location = '10,10'

Now do the same in PowerShell 7 Preview 4. You will see the exact failure. PS 7 needs to function this way to support WinForms and WinForms designers as well as legacy PS code.

To make this more explicit the following works in all previous versions of PowerShell:

[system.drawing.point]'10,10'
'
It does not work in PS7. Almost no uses like this fail in PS7 and yet are native to earlier versions of PowerShell.

@jvierrajrv Thanks! Please add repo steps in the issue description.

ISazonov Thank you for your response and rethink -

I posted a one line example that shows the issue clearly. Her eit is agai9n. Run the following line in PS 5.1 and PS 7 to see the error in PS 7.

[system.drawing.point]'10,10'

The issue affects many types including all of System.Drawing and System.Windows.Forms namespaces. Other namespaces that allow this are also affected but I have not spent time searching for more examples. All issues of this type are likely due to a parser extension that is missing as it was likely added in PS3. (just a guess). PS1 didn't have this. The Win 7 version of PS2 does have this capability.

It seems it is .Net Core issue.
.Net Framework assigns PointConverter to Point class by attribute
but .Net Core haven't this https://source.dot.net/#System.Drawing.Primitives/System/Drawing/Point.cs,14

It seems it is .Net Core issue.
.Net Framework assigns PointConverter to Point class by attribute
but .Net Core haven't this https://source.dot.net/#System.Drawing.Primitives/System/Drawing/Point.cs,14
Source Browser

I reported this at Preview 1 and it was ignored or maybe on the back burner. Ca you check and be sure it gets addressed?

Thankyou.

Yes - the code does show that it is Net COre. My issue is that PS 7 cannot reach a release state until this is addressed and the PS 7 team needs to take ownership of the issue to get the product released. I see that Net Core 3.1 is in preview and PS 7 seems to be using Core 4.0 with some assemblies showing RC1. I wonder if Core 3.1 will finally have this bit added?

I really would like to test many WinForms against 7 as soon as possible. Anticipation is killing me.

The whole PS 7 project is moving extremely well. It will be an excellent upgrade to PS 5.1 when ready. Keep up the good work.

Next WPF.

@jvierrajrv Please open the feature request in .Net Core and reference the issue so that we see and can vote too. All reference existence issue if you already have it.

@iSazonov I posted this to Net Core at PS Preview 1. They seemed to think it was a PS issue and apparently didn't act.

Can you have this moved to Net Core. I hoped to tickle the system to get someone to take ownership. The discussion here may get the Core people to understand the issue and understand why it has not been addressed.

@jvierrajrv Please add reference on your issue.

Sorry - I finally found the new navigation her and found the old issue.

https://github.com/PowerShell/PowerShell/issues/9815

The last response was June and suggested Core 3.0 would have the fix.

See also reference here #9863

Basically, .NET Core have altered their design, and our type converters need to be updated. @SteveL-MSFT, any chance of #9863 getting resolved in 7.0 timeframe? 馃檪

I see there is still more discussion and no resolution yet. Hopefully we can get it in 3.1 before it ships. There is really no way around this for testing existing PS scripts that use WinForms.

At least the notes seem to agree that it is critical to a PS7 final.

Thanks and good luck.

Ok, let's tracking in #9863

I didn't have that "watched" but am there now - thank you.

This issue has been marked as duplicate and has not had any activity for 1 day. It has been closed for housekeeping purposes.

Was this page helpful?
0 / 5 - 0 ratings