dotnet / dotnet/dotnet-api-docs

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

Aperta
#5,002 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub
area-System.ComponentModel.DataAnnotations Pri3 untriaged
Lingua principale
C#
Stelle
949
Fork
1.7k
Merge medio
2g 19h
PR unite (30g)
52

Descrizione

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.

Guida per i contributori

Apri la guida per i contributori

Direzione di ricerca

Iniziate dalla documentazione collegata di ValidationContext.MemberName e confrontate la relativa affermazione su .NET Framework 4.7.2 e versioni precedenti con il comportamento segnalato di ValidationAttribute personalizzato e l'impostazione aspnet:GetValidationMemberName. Confermate quali condizioni del framework/runtime spiegano la discrepanza, quindi aggiornate la documentazione per indicare accuratamente il comportamento e i requisiti di configurazione.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
csharp
Ambito
documentation
Tipo di issue
Documentazione
Difficoltà
3/5
Tempo stimato
1-2 giorni
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
38/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.