HandyOrg / HandyOrg/HandyControl

hc:Window 窗体在构造函数或 Loaded 函数中调用 this.Close(); 会导致报错

Open
#1,609 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C#
Stars
7.2k
Forks
1.2k
PR merge metrics
No merged PRs in 30d

Description

Describe the bug

hc:Window 窗体在构造函数或 Loaded 函数中调用 this.Close(); 会导致报错
System.NullReferenceException:“Object reference not set to an instance of an object.”

Steps to reproduce the bug
var window = new Window1();
window.ShowDialog();
public partial class Window1
{
    public Window1()
    {
        InitializeComponent();

        this.Loaded += Window1_Loaded;
    }

    private void Window1_Loaded(object sender, RoutedEventArgs e)
    {
        this.Close();
    }
}
Expected behavior

No response

Screenshots

No response

NuGet package version

None

IDE

Visual Studio 2022

Framework type

.Net 6.0

Windows version

No response

Additional context

No response

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the issue with the provided Window1 constructor, Loaded handler, and ShowDialog() call, then trace the hc:Window Close path reached during loading. Confirm that closing from the constructor or Loaded handler no longer raises NullReferenceException; the payload does not name a source file or test to run.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
desktop
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.