dotnet / dotnet/wpf

When using class-level-validation via `INotifyDataErrorInfo` every entry is shown twice

Open
#4,201 0 comments 2 reactions 0 assignees View on GitHub
Investigate
Dominant language
C#
Stars
7.7k
Forks
1.3k
Avg merge
1d 11h
Merged PRs (30d)
61

Description

* .NET Core Version: 5.0.103
* Windows version: 10.0.19042
* Does the bug reproduce also in WPF for .NET Framework 4.8?: Yes
* Is this bug related specifically to tooling in Visual Studio (e.g. XAML Designer, Code editing, etc...)? No
* Security issues and bugs should be reported privately, learn more via our [responsible disclosure guidelines](https://github.com/dotnet/wpf/blob/master/README.md#reporting-security-issues-and-security-bugs).



**Problem description:**
If you bind to a class which implements `INotifyDataErrorInfo` it runs validation for the whole class. It should show the issue for each property once, but shows it twice.

**Actual behavior:**
Every issue is shown twice like shown in the following image:
![image](https://user-images.githubusercontent.com/47110241/108717921-2418b600-751e-11eb-93fb-b4ea6b7439d3.png)

Investigating this further showed that the method `GetErrors(string propertyName)` gets calles twice. One time for `null` and one time for `string.Empty`. According to the docs both calls will return the same result: https://docs.microsoft.com/en-us/dotnet/api/system.componentmodel.inotifydataerrorinfo.geterrors?view=net-5.0

> "The name of the property to retrieve validation errors for; or null or Empty, to retrieve entity-level errors."

I also discussed this here as I first thought it was a bug there: https://github.com/windows-toolkit/WindowsCommunityToolkit/issues/3763

**Expected behavior:**
Every issue is shown only once.

**Minimal repro:**
https://github.com/timunie/MvvmToolkitValidationSample

Thank you and happy coding
Tim

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.