dotnet / winforms

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

When the helpNamespace property in helpProvider is blank after delete the previous saved URL, project exit from runtime automatically when press F1 #11583

Open Liv-Goh opened 4 days ago

Liv-Goh commented 4 days ago

.NET version

.NET 9.0 SDK build: 9.0.100-preview.7.24321.3

Did it work in .NET Framework?

Yes

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

Yes, this is a regression issue. Not reproduced on .NET 8.0

Issue description

Current Behavior (.NET 9.0): When the helpNamespace property in helpProvider is blank after delete the previous saved URL, project exit from runtime automatically when press F1 and no error exception popped out.

https://github.com/dotnet/winforms/assets/169347065/fb053321-b64c-4e64-ab81-9c72b4d5ffcf

Expected Behavior (.NET 8.0): When the helpNamespace property in helpProvider is blank after delete the previous saved URL, error exception popped out when press F1.

image

Steps to reproduce

1. Create a WinForms .NET 9.0 project
2. Add a button and helpProvider to form designer
3. Set button "showHelpOnHelpProvider1" property to True
4. Add a random URL (e.g. https://github.com/dotnet/winforms) to helpProvider "HelpNamespace" property, save
5. Delete URL in "HelpNamespace", save
6. Run the project and press F1
elachlan commented 4 days ago

Issue is here: https://github.com/dotnet/winforms/blob/5ba64aeb545308babc843c8d4ecee1e069e85ead/src/System.Windows.Forms/src/System/Windows/Forms/Help/HelpProvider.cs#L130-L144

It should be:

if (!string.IsNullOrEmpty(HelpNamespace))
elachlan commented 4 days ago

@Liv-Goh two things:

Liv-Goh commented 4 days ago

@elachlan the test results are as below

  • What is the value of the HelpNamespace in the designer.cs?

HelpNamespace value is empty string in both .NET 8 and 9 image

  • What is the stack trace from .NET 8? (we should see what argument exception is thrown.)

System.ArgumentException HResult=0x80070057 Message=Help URL '' is not valid. (Parameter 'url') Source=System.Windows.Forms StackTrace: at System.Windows.Forms.Help.ShowHTMLFile(Control parent, String url, HelpNavigator command, Object param) at System.Windows.Forms.HelpProvider.OnControlHelp(Object sender, HelpEventArgs hevent) at System.Windows.Forms.Control.OnHelpRequested(HelpEventArgs hevent) at System.Windows.Forms.Control.WmHelp(Message& m) at System.Windows.Forms.Control.WndProc(Message& m) at System.Windows.Forms.ButtonBase.WndProc(Message& m) at System.Windows.Forms.NativeWindow.Callback(HWND hWnd, MessageId msg, WPARAM wparam, LPARAM lparam)

elachlan commented 4 days ago

https://github.com/dotnet/winforms/blob/5ba64aeb545308babc843c8d4ecee1e069e85ead/src/System.Windows.Forms/src/System/Windows/Forms/Help/Help.cs#L53-L64

https://github.com/dotnet/winforms/blob/5ba64aeb545308babc843c8d4ecee1e069e85ead/src/System.Windows.Forms/src/System/Windows/Forms/Help/Help.cs#L290-L309

https://github.com/dotnet/winforms/blob/5ba64aeb545308babc843c8d4ecee1e069e85ead/src/System.Windows.Forms/src/System/Windows/Forms/Help/Help.cs#L194-L196

Help.GetHelpFileType probably needs to check for empty string instead of a standard null check. We also should probably throw ArugementNullException in ShowHTML10Help, like we do in ShowHTMLFile.

merriemcgaw commented 3 days ago

@elachlan would you like to work on this one, or should I assign a team member? This is definitely one I want to take for .NET 9.

elachlan commented 2 days ago

@merriemcgaw happy for someone else to take this on.

Tanya-Solyanik commented 20 hours ago

@LeafShi1 - could your teams please take a look?