dotnet / dotnet/dotnet-api-docs

Remarks on ValidationContext.MemberName don't appear to reflect reality

Open
#5,002 0 comments 0 reactions 0 assignees View on GitHub
area-System.ComponentModel.DataAnnotations Pri3 untriaged
Dominant language
C#
Stars
949
Forks
1.7k
Avg merge
3d 27m
Merged PRs (30d)
49

Description

https://docs.microsoft.com/en-us/dotnet/api/system.componentmodel.dataannotations.validationcontext.membername?view=netframework-4.6.1 states:

> In .NET Framework 4.7.2 and earlier versions, when using a custom System.ComponentModel.DataAnnotations.ValidationAttribute, the MemberName property returns null.

My .NET Framework web app has numerous custom `ValidationAttribute`s (I assume "custom" = "derived from") and the `MemberName` property is very much non-null on the `ValidationContext`s passed into those attributes' overridden `IsValid(object, ValidationContext)` method. The catch is that (a) the app targets Framework 4.6.1 (b) there is no `aspnet:GetValidationMemberName` setting defined in its `web.config` file. In other words, what I'm seeing directly contradicts what the documentation claims.

I have the following Framework versions installed:

.NET FW 3.5 SP 1 (CLR 2.0)
.NET FW 4.6.2 Windows 10 May 2020 Update(CLR 4.0)
.NET FW 4.7 Windows 10 May 2020 Update(CLR 4.0)
.NET FW 4.7.1 Windows 10 May 2020 Update(CLR 4.0)
.NET FW 4.7.2 Windows 10 May 2020 Update(CLR 4.0)
.NET FW 4.8 Windows 10 May 2020 Update(CLR 4.0)

so my assumption is that my app is actually being run by 4.8, but even so that does not explain the missing `web.config` setting.

Please can you advise why this is working for me, and/or update the documentation to clarify.

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.