dotnet / dotnet/wpf

Unhelpful NullReferenceException when a PageFunction has no default constructor

Open
#4,313 1 comment 2 reactions 0 assignees View on GitHub
.NET Framework
Dominant language
C#
Stars
7.7k
Forks
1.3k
Avg merge
1d 11h
Merged PRs (30d)
61

Description

* .NET Core Version: 5
* Windows version: 20H2 Build 19402.867


**Problem description:** A page function that has no default constructor and is not kept alive is returned to with `OnReturn()`

**Actual behavior:** A `NullReferenceException` is thrown in [BindToMethod](https://github.com/dotnet/runtime/blob/main/src/libraries/System.Private.CoreLib/src/System/DefaultBinder.cs#L30).

**Expected behavior:** An exception with an error message that helps tracking down the problem is thrown.

The `NullReferenceException` happens because [CreateInstanceWithCtor](https://github.com/dotnet/wpf/blob/main/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/Runtime/DynamicMethodRuntime.cs#L193) calls `BindToMethod` and passes the `args` which are `null` but `BindToMethod` assumes that `args` is not null.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.