Skip to content

ValidationAttribute.SetResourceAccessorByPropertyLookup should throw better exception #44292

Closed

Description

@krwq

Converting TODO-NULLABLE into the issue here since I'm not familiar with the area I'll leave it for area owner to decide if they want to close it or leave it. I'll remove the original comment in case it's decided this should be closed.

In ValidationAttribute.SetResourceAccessorByPropertyLookup (last line):

_errorMessageResourceAccessor = () => (string)property.GetValue(null, null)!;

Is commented as If the user-provided resource returns null, an ArgumentNullException is thrown - should probably throw a better exception

Activity

  1. ajcvickers commented on Jul 13, 2021

    @ajcvickers
    Contributor

    @roji Can you take a quick look at this along with the other nullable cleanup?

  2. added this to the 6.0.0 milestone on Jul 13, 2021
  3. removed
    untriagedNew issue has not been triaged by the area owner
    on Jul 13, 2021
  4. roji commented on Jul 14, 2021

    @roji
    Member

    This basically means that if the user sets up the validation attribute to point at a resource accessor, and the property returns null, attempts to format an error message will fail with ArgumentNullException. This is incorrect/unsupported usage by the user, so barring changing the exception to be slightly more informative I don't think there's anything to do.

  5. removed this from the 6.0.0 milestone on Jul 14, 2021
  6. ghost locked as resolved and limited conversation to collaborators on Aug 13, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions