Bug 18265 - Data Annotations ValidationContext doesn't handle the Display attribute
Summary: Data Annotations ValidationContext doesn't handle the Display attribute
Status: RESOLVED FIXED
Alias: None
Product: Class Libraries
Classification: Mono
Component: General ()
Version: master
Hardware: All All
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2014-03-08 21:13 UTC by Brian Surowiec
Modified: 2014-11-25 05:06 UTC (History)
2 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on GitHub or Developer Community with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED FIXED

Description Brian Surowiec 2014-03-08 21:13:57 UTC
Currently System.ComponentModel.DataAnnotations.ValidationContext always sets its DisplayName property to the type name. This is inconsistent with the .NET implementation. This is the line where the issue comes from
https://github.com/mono/mono/blob/81573de69dc83dd878cbc956f2847903d2610c03/mcs/class/System.ComponentModel.DataAnnotations/System.ComponentModel.DataAnnotations/ValidationContext.cs#L57

On .NET the DisplayName is set based on the DisplayAttribute of the member being validated. If one isn't used then it falls back to the member name. And if that's not available, such as when calling a class level validator, it then uses the type name.

I ran into this while building out the DataAnnotations support in NancyFX. My workaround can be seen here https://github.com/xt0rted/Nancy/blob/b540b5b07326964d52b82660d59ae50ad0fdd77b/src/Nancy.Validation.DataAnnotations/DataAnnotationsValidatorAdapter.cs#L66-73

It should be noted that in order to better understand how this was working and what needed to be fixed I did look at the source code for the ValidationContent class on http://referencesource.microsoft.com, though my implementation is not the same as theirs.
Comment 1 Marek Safar 2014-11-25 05:06:46 UTC
Resolved in master