dotnet / winforms

Windows Forms is a .NET UI framework for building Windows desktop applications.
MIT License
4.32k stars 958 forks source link

Undo in DemoConsole clears all item in ListView instead of undo previous move #11657

Closed Liv-Goh closed 2 days ago

Liv-Goh commented 3 weeks ago

.NET version

.NET 9.0 main branch of WinForms repo

Did it work in .NET Framework?

Not tested/verified

Did it work in any of the earlier releases of .NET Core or .NET 5+?

Yes, this is a regression issue. Not repro on .NET 8.0 from Release/8.0 branch of WinForms repo

Issue description

Current Behavior (.NET 9.0) : In DemoConsole test app of WinForms repo, undo a move that perform on ListView clears all item in ListView instead of undo previous move. demoConsoleUndoListViewCurrent

Expected Behavior (.NET 8.0) : In DemoConsole test app of WinForms repo, undo a move that perform on ListView will undo previous move. demoConsoleUndoListViewExpected

Steps to reproduce

Test sample: DemoConsole in Winforms repo

  1. Open ListView smart tag and click 'Edit Items'
  2. Add item into the ListView and click OK
  3. Repeat step 1 -2
  4. Click Undo / Ctrl + Z

More Info

  1. Edit and delete item on ListView also cannot be undo, undo will clear all the items in ListView.
  2. Tree View in DemoConsole also have the same issue with undo
  3. ListBox and DataGridView in DemoConsole does not have this issue with undo
elachlan commented 3 weeks ago

@Liv-Goh does #11614 fix this?

Liv-Goh commented 3 weeks ago

@Liv-Goh does #11614 fix this?

@elachlan No, the issue still repro on https://github.com/dotnet/winforms/pull/11614 branch

ricardobossan commented 1 week ago

Stack trace:

   at System.ComponentModel.Design.Serialization.CodeDomSerializerBase.Error(IDesignerSerializationManager manager, String exceptionText, String helpLink) in C:\Users\v-rbossan\source\repos\winforms\11657\src\System.Windows.Forms.Design\src\System\ComponentModel\Design\Serialization\CodeDomSerializerBase.cs:line 175
   at System.ComponentModel.Design.Serialization.CodeDomSerializerBase.DeserializeExpression(IDesignerSerializationManager manager, String name, CodeExpression expression) in C:\Users\v-rbossan\source\repos\winforms\11657\src\System.Windows.Forms.Design\src\System\ComponentModel\Design\Serialization\CodeDomSerializerBase.cs:line 916
   at System.ComponentModel.Design.Serialization.CodeDomSerializerBase.DeserializeExpression(IDesignerSerializationManager manager, String name, CodeExpression expression) in C:\Users\v-rbossan\source\repos\winforms\11657\src\System.Windows.Forms.Design\src\System\ComponentModel\Design\Serialization\CodeDomSerializerBase.cs:line 962
JeremyKuhne commented 1 week ago

We're dependent on BinaryFormatter for CodeDomSerialization. Validated this doesn't happen with the package reference added.

Liv-Goh commented 1 week ago

Verified the issue on the latest DemoConsole test app of Winforms repo from main branch, the issue still repro, ListView clears all item in ListView instead of undo previous move. DemoConsoleUndoIssue2

JeremyKuhne commented 3 days ago

Sorry, I misread this. An exception is being thrown here:

>   System.Windows.Forms.Design.dll!System.ComponentModel.Design.Serialization.CodeDomSerializerBase.Error(System.ComponentModel.Design.Serialization.IDesignerSerializationManager manager, string exceptionText, string helpLink) Line 175    C#
    System.Windows.Forms.Design.dll!System.ComponentModel.Design.Serialization.CodeDomSerializerBase.DeserializeExpression(System.ComponentModel.Design.Serialization.IDesignerSerializationManager manager, string name, System.CodeDom.CodeExpression expression) Line 916    C#
    System.Windows.Forms.Design.dll!System.ComponentModel.Design.Serialization.CodeDomSerializerBase.DeserializeExpression(System.ComponentModel.Design.Serialization.IDesignerSerializationManager manager, string name, System.CodeDom.CodeExpression expression) Line 962    C#
    System.Windows.Forms.Design.dll!System.ComponentModel.Design.Serialization.CodeDomSerializerBase.DeserializeExpression(System.ComponentModel.Design.Serialization.IDesignerSerializationManager manager, string name, System.CodeDom.CodeExpression expression) Line 845    C#
    System.Windows.Forms.Design.dll!System.ComponentModel.Design.Serialization.CodeDomSerializerBase.DeserializeStatement(System.ComponentModel.Design.Serialization.IDesignerSerializationManager manager, System.CodeDom.CodeStatement statement) Line 424    C#
    System.Windows.Forms.Design.dll!System.ComponentModel.Design.Serialization.CodeDomComponentSerializationService.CodeDomSerializationStore.ComponentListCodeDomSerializer.ResolveName(System.ComponentModel.Design.Serialization.IDesignerSerializationManager manager, string name, bool canInvokeManager) Line 313 C#
    System.Windows.Forms.Design.dll!System.ComponentModel.Design.Serialization.CodeDomComponentSerializationService.CodeDomSerializationStore.ComponentListCodeDomSerializer.Deserialize(System.ComponentModel.Design.Serialization.IDesignerSerializationManager manager, System.Collections.Generic.Dictionary<string, System.ComponentModel.Design.Serialization.CodeDomComponentSerializationService.CodeDomComponentSerializationState> objectState, System.Collections.Generic.List<string> objectNames, bool applyDefaults) Line 101 C#
    System.Windows.Forms.Design.dll!System.ComponentModel.Design.Serialization.CodeDomComponentSerializationService.CodeDomSerializationStore.Deserialize(System.IServiceProvider provider, System.ComponentModel.IContainer container, bool validateRecycledTypes, bool applyDefaults, System.Collections.Generic.List<object> objects) Line 251   C#
    System.Windows.Forms.Design.dll!System.ComponentModel.Design.Serialization.CodeDomComponentSerializationService.CodeDomSerializationStore.DeserializeTo(System.IServiceProvider provider, System.ComponentModel.IContainer container, bool validateRecycledTypes, bool applyDefaults) Line 274  C#
    System.Windows.Forms.Design.dll!System.ComponentModel.Design.Serialization.CodeDomComponentSerializationService.DeserializeTo(System.ComponentModel.Design.Serialization.SerializationStore store, System.ComponentModel.IContainer container, bool validateRecycledTypes, bool applyDefaults) Line 177 C#
    System.ComponentModel.TypeConverter.dll!System.ComponentModel.Design.Serialization.ComponentSerializationService.DeserializeTo(System.ComponentModel.Design.Serialization.SerializationStore store, System.ComponentModel.IContainer container) Unknown
    System.Windows.Forms.Design.dll!System.ComponentModel.Design.UndoEngine.UndoUnit.ChangeUndoEvent.Undo(System.ComponentModel.Design.UndoEngine engine) Line 148  C#
    System.Windows.Forms.Design.dll!System.ComponentModel.Design.UndoEngine.UndoUnit.UndoCore() Line 424    C#
    System.Windows.Forms.Design.dll!System.ComponentModel.Design.UndoEngine.UndoUnit.Undo() Line 369    C#
    DesignSurfaceExt.dll!DesignSurfaceExt.UndoEngineExt.Undo() Line 29  C#
    DesignSurface.dll!TestConsole.MainForm.undoToolStripMenuItem_Click(object sender, System.EventArgs e) Line 340  C#

It looks like the variable name isn't right. This appears to be fallout from #11062, I'm looking further into it.

MelonWang1 commented 2 days ago

Verified this issue on winforms repo from main branch, it was fixed: undo a move that perform on ListView will undo previous move.

https://github.com/user-attachments/assets/9da4320f-1d4c-459a-8edb-90e31ee30d8d