Standard-Toolkit icon indicating copy to clipboard operation
Standard-Toolkit copied to clipboard

[Bug]: CheckedListBox CheckedIndices NullRef

Open iwarp opened this issue 1 year ago • 2 comments

Describe the bug Just converting an existing app using Krypton to the standard-toolkit, when looping thru the CheckedIndices of a CheckedListBox I get a null ref issue in multiple places across my code base.

StackTrace: at Krypton.Toolkit.KryptonCheckedListBox.InternalCheckedListBox.InnerArrayIndexOfIdentifier(Object identifier, Int32 stateMask) in C:\git\Krypton-Standard-Toolkit\Source\Krypton Components\Krypton.Toolkit\Controls Toolkit\KryptonCheckedListBox.cs:line 759 at Krypton.Toolkit.KryptonCheckedListBox.CheckedIndexCollection.InnerArrayIndexOfIdentifier(Object identifier, Int32 stateMask) in C:\git\Krypton-Standard-Toolkit\Source\Krypton Components\Krypton.Toolkit\Controls Toolkit\KryptonCheckedListBox.cs:line 153 at Krypton.Toolkit.KryptonCheckedListBox.CheckedIndexCollection.get_Item(Int32 index) in C:\git\Krypton-Standard-Toolkit\Source\Krypton Components\Krypton.Toolkit\Controls Toolkit\KryptonCheckedListBox.cs:line 127 at Krypton.Toolkit.KryptonCheckedListBox.CheckedIndexCollection.CopyTo(Array array, Int32 index) in C:\git\Krypton-Standard-Toolkit\Source\Krypton Components\Krypton.Toolkit\Controls Toolkit\KryptonCheckedListBox.cs:line 70 at Krypton.Toolkit.KryptonCheckedListBox.CheckedIndexCollection.GetEnumerator() in C:\git\Krypton-Standard-Toolkit\Source\Krypton Components\Krypton.Toolkit\Controls Toolkit\KryptonCheckedListBox.cs:line 81 at KryptonTest.Form1.kryptonButton1_Click(Object sender, EventArgs e) in

To Reproduce Simple form with CheckedListBox with Designer added items.

foreach(var item in this.kryptonCheckedListBox1.CheckedIndices) { MessageBox.Show(item.ToString()); }

Expected behavior Not to crash and return the selected indexes back to my foreach

Desktop (please complete the following information):

  • OS: Windows 11
  • Version: 10.0.22621.3007
  • Framework/.NET Version: 6, 7 and 8
  • Toolkit Version: Tried switching across a lot of them they all have the same issue.

Possible Resolution image When this method is executed its dynamically loading the method for "IndexOfIdentifier" however there is no method named that on a ItemArray.

List of Method on the ItemArray InnerArray.GetType().GetMethods() {System.Reflection.MethodInfo[25]} [0]: {Boolean GetState(Int32, Int32)} [1]: {Void SetState(Int32, Int32, Boolean)} [2]: {Int32 GetCount(Int32)} [3]: {Int32 get_Version()} [4]: {System.Object Add(System.Object)} [5]: {Void Clear()} [6]: {Int32 CreateMask()} [7]: {Int32 GetActualIndex(Int32, Int32)} [8]: {Int32 get_Count()} [9]: {System.Collections.IEnumerator GetEnumerator(Int32)} [10]: {System.Collections.IEnumerator GetEnumerator(Int32, Boolean)} [11]: {System.Object GetItem(Int32, Int32)} [12]: {Int32 IndexOf(System.Object, Int32)} [13]: {Void Insert(Int32, System.Object)} [14]: {Void InsertEntry(Int32, Entry)} [15]: {Void Remove(System.Object)} [16]: {Void RemoveAt(Int32)} [17]: {Void SetItem(Int32, System.Object)} [18]: {Entry GetEntry(System.Object)} [19]: {Int32 BinarySearch(Entry)} [20]: {Void Sort()} [21]: {System.Type GetType()} [22]: {System.String ToString()} [23]: {Boolean Equals(System.Object)} [24]: {Int32 GetHashCode()}

This problem can be fixed if the Method name is switched to "IndexOf" instead. https://github.com/Krypton-Suite/Standard-Toolkit/blob/4c38c8492a2290291047e2f668fa17efe8417931/Source/Krypton%20Components/Krypton.Toolkit/Controls%20Toolkit/KryptonCheckedListBox.cs#L756

iwarp avatar Feb 04 '24 05:02 iwarp

I'm confused... There is already a redirect for the IndexOf in the API above that...

image

Why is that not being used ?

Notes: IndexOfIdentifier does exist for .net image

You used the API list from List of Method on the ItemArray which is not a ListBox.

@iwarp Can you add an example of your "Designer added items" please ?

Smurf-IV avatar Feb 24 '24 14:02 Smurf-IV

@Smurf-IV simple demo of the bug here https://github.com/iwarp/KryptonBugDemo check some items and hit the button.

Designer Added Items is super simple. kryptonCheckedListBox1.Items.AddRange(new object[] { "Test1", "Test2", "Test3", "Test4", "Test5" });

iwarp avatar Feb 24 '24 19:02 iwarp

Argg.. It worked in <= .net48 image

So it must be a netcore core "Improvement" thing

Smurf-IV avatar Mar 03 '24 08:03 Smurf-IV

Top is the type from net48 Bottom is the type in netCore image

Smurf-IV avatar Mar 03 '24 08:03 Smurf-IV

It was changed during the preview of netCore 6 !! https://github.com/dotnet/winforms/commit/1f4a593a6de32e75ff0f5fa97d35191c1facbc93

Because the ItemArray was drastically chnaged: https://github.com/dotnet/winforms/commit/1f4a593a6de32e75ff0f5fa97d35191c1facbc93#diff-fc2945ee2669ddb08500f48c7ae59bf19b266a27ffba223da89958e97924695a

Smurf-IV avatar Mar 03 '24 09:03 Smurf-IV

@Wagnerp Should this be retrofitted into V80 as it is a regression issue ?

Smurf-IV avatar Mar 03 '24 10:03 Smurf-IV

@Wagnerp Should this be retrofitted into V80 as it is a regression issue ?

@Smurf-IV How 'big' are the changes, as it may mess up the merging flow?

PWagner1 avatar Mar 03 '24 10:03 PWagner1

Should be the same as the ones in this PR.

Smurf-IV avatar Mar 03 '24 11:03 Smurf-IV

Should be the same as the ones in this PR.

@Smurf-IV Yes, but it should not be pushed to master, as it would mean that master would be 'ahead' of everything else.

PWagner1 avatar Mar 04 '24 07:03 PWagner1

Just theses changes, as a separate PR (Not a merge), will indicate in GitHub that it has a different code base (i.e. 1 change with how ever many files) Then when the V90 is merged later in the year, it will just replace over as usual.

Smurf-IV avatar Mar 05 '24 07:03 Smurf-IV

Thanks for getting to the bottom of this, is this now in nightly for me to test out? 90.24.3.64-alpha?

iwarp avatar Mar 05 '24 07:03 iwarp

Just theses changes, as a separate PR (Not a merge), will indicate in GitHub that it has a different code base (i.e. 1 change with how ever many files) Then when the V90 is merged later in the year, it will just replace over as usual.

Going to put it in a separate branch called master-patch-2

PWagner1 avatar Mar 05 '24 07:03 PWagner1

Thanks for getting to the bottom of this, is this now in nightly for me to test out? 90.24.3.64-alpha?

@iwarp Yes, but fixes have been applied to 80.24.3.64, if you need a stable version.

PWagner1 avatar Mar 05 '24 07:03 PWagner1