Skip to content

Inconsequent default message handling in system validator attributes  #68644

Open
@bang75

Description

@bang75

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

Is there a the reason for example EmailAdressAttribute sets DefaultMessage in constructor while RequiredAttibute sets the ErrorMessageAccessor?
I think this is inconsequent and might be a bug. Makes it harder to extend Validators with eg. a custom IValidationMetadataProvider.

Would also be nice if DefaultErrorMessage was public instead of internal ;)

public RequiredAttribute() : base(() => DataAnnotationsResources.RequiredAttribute_ValidationError)
{
}

...

public EmailAddressAttribute() : base(DataType.EmailAddress)
{
  // Set DefaultErrorMessage not ErrorMessage, allowing user to set
  // ErrorMessageResourceType and ErrorMessageResourceName to use localized messages.
  DefaultErrorMessage = SR.EmailAddressAttribute_Invalid;
}

Expected Behavior

No response

Steps To Reproduce

No response

Exceptions (if any)

No response

.NET Version

6

Anything else?

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions