Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: Getting an application crash when pressing the Delete key. #1373

Closed
Tape-Worm opened this issue Mar 14, 2024 · 43 comments
Closed

[Bug]: Getting an application crash when pressing the Delete key. #1373

Tape-Worm opened this issue Mar 14, 2024 · 43 comments
Labels
area:ribbon All issues to do with the ribbon. area:toolkit All issues related to the toolkit components. bug Something isn't working fixed This issue has been fixed. version:85-lts All things to do with V85 LTS. version:90 All things to do with V90.

Comments

@Tape-Worm
Copy link

Tape-Worm commented Mar 14, 2024

Describe the bug
In my application, I have a grid containing a list of files. I also have a Krypton ribbon present. When I press my delete key, I expect the application to ask me if I want to delete the file.

Instead, what happens is an unhandled exception is thrown. This is weird, because my code should have trapped the exception. It did not.

Here is the stack trace that is given on the crash:

Error Message: Unable to cast object of type 'System.Collections.Generic.Dictionary`2[System.Windows.Forms.Keys,System.Windows.Forms.ToolStripMenuItem]' to type 'System.Collections.Hashtable'.
Exception Type:  System.InvalidCastException
Source:  System.Private.CoreLib
Target Site:  System.Runtime.CompilerServices.CastHelpers.ChkCast_Helper
Stack trace
   at Gorgon.Editor.Program.Main(String[] args) in Program.cs:line 197
   at Gorgon.UI.GorgonApplication.Run(ApplicationContext context, Func`1 idleMethod) in GorgonApplication.cs:line 782
   at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(msoloop reason, ApplicationContext context)
   at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(msoloop reason, ApplicationContext context)
   at System.Windows.Forms.Application.ComponentManager.Microsoft.Office.IMsoComponentManager.FPushMessageLoop(UIntPtr dwComponentID, msoloop uReason, Void* pvLoopData)
   at System.Windows.Forms.Application.ThreadContext.Microsoft.Office.IMsoComponent.FPreTranslateMessage(MSG* msg)
   at System.Windows.Forms.Application.ThreadContext.PreTranslateMessage(MSG& msg)
   at System.Windows.Forms.Application.ThreadContext.ProcessFilters(MSG& msg, Boolean& modified)
   at Krypton.Ribbon.KryptonRibbon.PreFilterMessage(Message& m)
   at Krypton.Ribbon.KryptonRibbon.ProcessCmdKey(Message& msg, Keys keyData)
   at Krypton.Ribbon.KryptonRibbonTab.ProcessCmdKey(Message& msg, Keys keyData)
   at Krypton.Ribbon.KryptonRibbonGroup.ProcessCmdKey(Message& msg, Keys keyData)
   at Krypton.Ribbon.KryptonRibbonGroupTriple.ProcessCmdKey(Message& msg, Keys keyData)
   at Krypton.Ribbon.KryptonRibbonGroupButton.ProcessCmdKey(Message& msg, Keys keyData)
   at Krypton.Toolkit.CommonHelper.CheckContextMenuForShortcut(ContextMenuStrip cms, Message& msg, Keys keyData)
<<<END>>>

As you can see, it ends up in a Krypton Toolkit Helper class.

  • Framework/.NET Version: [8.0]
  • Toolkit Version: [80.23.11.321]

Additional context
@Wagnerp , since you forked my repo, you can reproduce this in the Gorgon Editor application. Just create a new file and then select it in the file pane and press your delete key. If you get the develop branch, you'll get the .NET 8 version.

@Tape-Worm Tape-Worm added the bug Something isn't working label Mar 14, 2024
@PWagner1
Copy link
Contributor

Hi @Tape-Worm

This might be a errant null check within the Krypton Toolkit. Is the behaviour the same in any other framework versions?

@Tape-Worm
Copy link
Author

Tape-Worm commented Mar 15, 2024

.NET 6.0 with krypton version 5.550.2103, works as expected. No error.

.NET 6.0 with krypton version 80.23.11.321, works as expected. No error.

.NET 8.0 with krypton version 5.550.2103, crashes.

Seems this is only occurring on .NET 8.

@PWagner1
Copy link
Contributor

Hi @Tape-Worm

Are there any instructions on how to compile Gorgon, as every time I try to compile, I run into 'library' missing errors?

@Tape-Worm
Copy link
Author

Did you update the submodules?

@PWagner1
Copy link
Contributor

PWagner1 commented Mar 15, 2024

Did you update the submodules?

I've cloned the copy of your development branch. The only thing I updated is Krypton.Ribbon as we pushed an minor update out about a week ago.

image

image

@PWagner1
Copy link
Contributor

Getting a lot of D3DImage errors

image

@PWagner1
Copy link
Contributor

Does it require the DirectX SDK to be installed?

@Tape-Worm
Copy link
Author

Tape-Worm commented Mar 15, 2024

Nope. It shouldn't. I don't have it installed.

You may need to do this?
https://allthings.how/how-to-install-and-use-directx-graphics-tools-on-windows-11/

The article looks to be a little out of date, the Optional Features is now located under "System".
image

@PWagner1
Copy link
Contributor

Nope. It shouldn't. I don't have it installed.

You may need to do this? https://allthings.how/how-to-install-and-use-directx-graphics-tools-on-windows-11/

The article looks to be a little out of date, the Optional Features is now located under "System". image

I thought that is was odd that I couldn't find it

@Tape-Worm
Copy link
Author

Tape-Worm commented Mar 15, 2024

So, I just pulled it down to a neutral location on my harddrive, and it compiles just fine. I did run into a problem at first because I had put it under a directory with spaces in the name. Once I moved it out of there, it compiled fine.

The spaces in path problem is now fixed in develop. That was a major pain, thanks for pushing me to find it. :)

@Tape-Worm
Copy link
Author

Oh, I should also warn you that you may see an error about RoboCopy, just Build again if that pops up. I dunno why it doesn't work sometimes.

@PWagner1
Copy link
Contributor

Interesting, I still can't compile the dependencies, as the GlassCube.WPF project blocks it.

image

Unloading the WPF projects fixes this, but still can't quite get my head around the AppHost problem?

@Tape-Worm
Copy link
Author

Tape-Worm commented Mar 16, 2024

I have no idea what "AppHost" is. Although, it seems to be something to do with the C++/CLI compiler:
https://learn.microsoft.com/en-us/dotnet/core/tools/sdk-errors/netsdk1145

The Microsoft.Wpf.Interop.DirectX_winsdk is a C++/CLI assembly (you can thank Microsoft for this stupid decision). Do you have the C++ components installed? It needs the v143 platform toolset.

The GlassCube.WPF assembly won't compile without that Microsoft.Wpf.Interop.DirectX_winsdk assembly, so that's why it was failing. Honestly, you don't need it for this use case, just remove Microsoft.Wpf.Interop.DirectX_winsdk, Gorgon.Graphics.WPF and GlassCube.WPF.

It should compile after that.


I just tried on my work computer, which has never had Gorgon on it before, and it worked fine. So I'm guessing there's something missing with your installation of VS.

@PWagner1
Copy link
Contributor

Do you have the C++ components installed? It needs the v143 platform toolset.

I've now got C++/CLI stuff installing. If that fails, then I'll try it in one of my VMs.

@Tape-Worm
Copy link
Author

Just FYI, I also had it crash while I was holding down the CTRL key to zoom in on something. Same stack trace.

@PWagner1
Copy link
Contributor

@Tape-Worm I haven't forgotten about this, been fixing/implementing new stuff recently.

@Tape-Worm
Copy link
Author

Tape-Worm commented Mar 26, 2024

No worries my friend. I'm currently doing a major upgrade to .NET 8, and it'll take quite some time before I hit the UI related stuff.

@giduac
Copy link
Contributor

giduac commented Jun 19, 2024

Hi @Tape-Worm,

I've been looking into another datagrid issue #1280.
Here also a bug has been reported using Toolkit Version: 80.23.11.321.

When testing with TK 80.24.3.64 I didn't get the error,
Tested this with Net 48 / 6 / 7 / 8

Could you give that TK version a try please ?

@giduac
Copy link
Contributor

giduac commented Jul 2, 2024

@Wagnerp or @Smurf-IV,

No response received from @Tape-Worm.
Please close the ticket. If needed it can be reopened.

ty.

@PWagner1 PWagner1 closed this as completed Jul 2, 2024
@Tape-Worm
Copy link
Author

Tape-Worm commented Jul 10, 2024

@giduac, @Wagnerp , @Smurf-IV

Sorry, I've been plagued with health issues and my partner and I have been dealing with her cancer diagnosis and subsequent treatment (she's all clear now). So, I haven't been paying much attention to programming for the last few months.

I just updated to the latest version on nuget, 85.24.6.176, and I'm still getting the exception. I am not using anything other than the Krypton Form (for the main window only), and the ribbon. Any data grids I have are the basic .NET data grids that come with windows forms.

image

Error Message: Unable to cast object of type 'System.Collections.Generic.Dictionary`2[System.Windows.Forms.Keys,System.Windows.Forms.ToolStripMenuItem]' to type 'System.Collections.Hashtable'.
Exception Type:  System.InvalidCastException
Source:  System.Private.CoreLib
Target Site:  System.Runtime.CompilerServices.CastHelpers.ChkCast_Helper
Stack trace
   at Gorgon.Editor.Program.Main(String[] args) in Program.cs:line 193
   at Gorgon.UI.GorgonApplication.Run(ApplicationContext context, Func`1 idleMethod) in GorgonApplication.cs:line 773
   at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(msoloop reason, ApplicationContext context)
   at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(msoloop reason, ApplicationContext context)
   at System.Windows.Forms.Application.ComponentManager.Microsoft.Office.IMsoComponentManager.FPushMessageLoop(UIntPtr dwComponentID, msoloop uReason, Void* pvLoopData)
   at System.Windows.Forms.Application.ThreadContext.Microsoft.Office.IMsoComponent.FPreTranslateMessage(MSG* msg)
   at System.Windows.Forms.Application.ThreadContext.PreTranslateMessage(MSG& msg)
   at System.Windows.Forms.Application.ThreadContext.ProcessFilters(MSG& msg, Boolean& modified)
   at Krypton.Ribbon.KryptonRibbon.PreFilterMessage(Message& m)
   at Krypton.Ribbon.KryptonRibbon.ProcessCmdKey(Message& msg, Keys keyData)
   at Krypton.Ribbon.KryptonRibbonTab.ProcessCmdKey(Message& msg, Keys keyData)
   at Krypton.Ribbon.KryptonRibbonGroup.ProcessCmdKey(Message& msg, Keys keyData)
   at Krypton.Ribbon.KryptonRibbonGroupTriple.ProcessCmdKey(Message& msg, Keys keyData)
   at Krypton.Ribbon.KryptonRibbonGroupButton.ProcessCmdKey(Message& msg, Keys keyData)
   at Krypton.Toolkit.CommonHelper.CheckContextMenuForShortcut(ContextMenuStrip cms, Message& msg, Keys keyData)
<<<END>>>

@giduac
Copy link
Contributor

giduac commented Jul 10, 2024

Hi @Tape-Worm,
cc: @Wagnerp (please reopen the ticket, ty)

Sorry to hear that and wishing you all the best.

Thanks for responding I will look in to as soon as there's time (of which we don't have enough...)

@PWagner1 PWagner1 reopened this Jul 10, 2024
@PWagner1
Copy link
Contributor

Hi @giduac

I've reopened this, which version tag should I assign? I think it's something to do with the ribbon.

@Tape-Worm Sorry to hear that, wishing you and your partner all the best!

@PWagner1 PWagner1 added the area:ribbon All issues to do with the ribbon. label Jul 10, 2024
@giduac
Copy link
Contributor

giduac commented Jul 10, 2024

@Wagnerp , V85 & V90 tags

@PWagner1 PWagner1 added version:85-lts All things to do with V85 LTS. version:90 All things to do with V90. labels Jul 10, 2024
@giduac
Copy link
Contributor

giduac commented Jul 11, 2024

Hi @Tape-Worm,

Some questions for you:

  • Can you give some more context about the grid you are using and how this is setup.
  • When you press DEL is the focus on the grid?
  • You mention the ribbon, do you think there's a connection?
  • The trace shows: Error Message: Unable to cast object of type 'System.Collections.Generic.Dictionary2[System.Windows.Forms.Keys,System.Windows.Forms.ToolStripMenuItem]' to type 'System.Collections.Hashtable'.` What kind of cast is being performed in the code?
  • Can you reproduce the error in a test app that has nothing to do with the project you're working on?

@giduac
Copy link
Contributor

giduac commented Jul 15, 2024

@Tape-Worm Great!!
I'll get back to you...

@Tape-Worm
Copy link
Author

I should also note that the context strip menu was attached to a button on my ribbon:
this.ButtonCreate.ContextMenuStrip = this.MenuCreate;

You'll probably need to do something like this to cause it to crash in a small test app.

@giduac
Copy link
Contributor

giduac commented Jul 15, 2024

@Tape-Worm
If anything more comes to mind just drop a note please...

@Tape-Worm
Copy link
Author

You'll also need to set the button type to DropDown (which I guess kinda goes without saying considering we're hitting a context menu).

I just tried a small test app, which I've attached here. You'll need to point it at your Krypton DLLs as I have it pointing to mine on my local drive.

RibbonCrashRepo.zip

@Smurf-IV Smurf-IV assigned Smurf-IV and giduac and unassigned Smurf-IV Jul 15, 2024
@Smurf-IV Smurf-IV added this to the Version 85 milestone Jul 15, 2024
@Smurf-IV Smurf-IV added area:toolkit All issues related to the toolkit components. area:datagrid All issues related to the DataGrid. labels Jul 15, 2024
@giduac
Copy link
Contributor

giduac commented Jul 15, 2024

@Tape-Worm
A possible work-around, if you use a KryptonContextMenu the error does not happen.

In the mean while we'll be looking into it further since it's also a bit weird that the Ribbon processes the key stroke that's intended for the grid.

I'll keep you posted.

@Tape-Worm
Copy link
Author

Tape-Worm commented Jul 15, 2024

It has nothing to do with the grid. If you pull the grid out of that sample, and use the Krypton Ribbon Lite on nuget, you will get exactly the same issue. The grid has nothing to do with this.

The ribbon is processing all key strokes and checking to see if they are used on the attached context menu strip. That's all that function is doing.

I've attached another sample without a grid, and you'll see that it crashes just the same. Again, this has nothing to do with grids.

RibbonCrashRepo.zip

@giduac
Copy link
Contributor

giduac commented Jul 15, 2024

It has nothing to do with the grid. If you pull the grid out of that sample, and use the Krypton Ribbon Lite on nuget, you will get exactly the same issue. The grid has nothing to do with this.

The ribbon is processing all key strokes and checking to see if they are used on the attached context menu strip. That's all that function is doing.

I've attached another sample without a grid, and you'll see that it crashes just the same. Again, this has nothing to do with grids.

RibbonCrashRepo.zip

@Tape-Worm
I did try too without a grid and got the same error.
Although with a grid and the grid having the focus it's a bit weird that that key stroke ends up with that button.
Tried .Net 9 preview, same problem.
And upcoming Toolkit V90 has it also.

KryptonContextMenu gets a different treatment in the RibbonGroupButton code

if (ButtonType is GroupButtonType.DropDown or GroupButtonType.Split)
{
    if (KryptonContextMenu != null)
    {
        if (KryptonContextMenu.ProcessShortcut(keyData))
        {
            return true;
        }
    }

    if (ContextMenuStrip != null)
    {
        if (CommonHelper.CheckContextMenuForShortcut(ContextMenuStrip, ref msg, keyData))
        {
            return true;
        }
    }
}

Anyways will put your fix in asap

@Tape-Worm
Copy link
Author

Tape-Worm commented Jul 15, 2024

I have a custom tree with a standard text box that I use for renaming nodes. When that textbox is on screen, you'd think it'd have first crack at the input. Nope, it doesn't. The ribbon previews that as well.

To verify this, I took that sample app, and added a textbox. Just a standard basic textbox that comes with windows forms. When the app loads, I give focus to the textbox and hit 'A' and boom, crash again (using the current nuget version of the krypton ribbon).

For some reason the designers of this component have decided to intercept all keystrokes via the ribbon. I agree it's really strange. But not only that, it's potentially problematic because if I were to hit a key associated with a menu item, it will (I tested this as well) execute that menu items functionality. That breaks the rules of how focus works in an application.

I think this method needs to check to ensure that the ribbon has focus or something like that before it tries processing anything. Or better yet, stop capturing everything.

Re: The KryptonContextMenu.

I don't want to use any more Krypton controls than I'm currently using. Given the issues that I have right now, I'm on the fence as to whether I want to keep using this library or not. Adding more references just makes my life a lot harder. Also, I provide extensibility functionality in the application, and I want my users to have minimal interaction with a control set that they may be unfamiliar with or not want to use.

@Smurf-IV Smurf-IV added under investigation This bug/issue is currently under investigation. and removed area:datagrid All issues related to the DataGrid. labels Jul 16, 2024
@giduac
Copy link
Contributor

giduac commented Jul 16, 2024

Hi @Tape-Worm,
PRs are in

Re: The KryptonContextMenu.
I don't want to use any more Krypton controls than I'm currently using. Given the issues that I have right now, I'm on the fence as to whether I want to keep using this library or not. Adding more references just makes my life a lot harder. Also, I provide extensibility functionality in the application, and I want my users to have minimal interaction with a control set that they may be unfamiliar with or not want to use.

We are currently reducing open issues for the rest of V90. V100 will mostly encompass improving it further to raise the quality. If you have ideas for improvement then we are always interested to hear...

@Tape-Worm
Copy link
Author

Tape-Worm commented Jul 16, 2024

The main issue that's a major problem for me is the designer not working with the Ribbon (which I brought up a couple years back). At this point, I do not wish to put in support for .NET 4.8 just so I can create/edit a control (I also then have to litter my code with #if NET80_OR_GREATER conditionals, which I despise having to do).

But that's not relevant to this issue, I think we can safely close this now?

Thank you for your help.

@giduac
Copy link
Contributor

giduac commented Jul 17, 2024

You're welcome and thanks for your input @Tape-Worm.

Had a quick look yesterday and found 1 windows keyboard hook in the Toolkit and the Ribbon has it's own WndProc. Possible sources for these key captures. To be continued,,,,

Your PRs are merged.
If you're in need of this fix you can build nugets from the cloned repo using branch master-V85 in this case.

@giduac giduac closed this as completed Jul 17, 2024
@giduac giduac added fixed This issue has been fixed. and removed under investigation This bug/issue is currently under investigation. labels Jul 17, 2024
@giduac giduac modified the milestones: Version 85, Version 90 Jul 17, 2024
@giduac giduac removed their assignment Jul 17, 2024
@Tape-Worm
Copy link
Author

Your PRs are merged. If you're in need of this fix you can build nugets from the cloned repo using branch master-V85 in this case.

Thanks! I don't need it right away, so I can wait until you guys do another stable release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:ribbon All issues to do with the ribbon. area:toolkit All issues related to the toolkit components. bug Something isn't working fixed This issue has been fixed. version:85-lts All things to do with V85 LTS. version:90 All things to do with V90.
Projects
None yet
Development

No branches or pull requests

4 participants