Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

System.InvalidOperationException: Either ErrorMessageString or ErrorMessageResourceName must be set, but not both. #17379

Closed
1 task done
heshamyosry opened this issue Aug 16, 2023 · 0 comments · Fixed by #17423
Assignees
Milestone

Comments

@heshamyosry
Copy link

heshamyosry commented Aug 16, 2023

Is there an existing issue for this?

  • I have searched the existing issues

Description

I encountered a bug in "AbpModelMetadataProvider" where a System.InvalidOperationException is thrown with the following error message: "Either ErrorMessageString or ErrorMessageResourceName must be set, but not both."
This exception occurs when i use validation error messages from ResourceFile (.resx) on my DTOs

Reproduction Steps

Configure Dto validation like this

class DepartmentDto
{
        [Required(AllowEmptyStrings = false, ErrorMessageResourceType = typeof(Configuration_DepartmentResource), ErrorMessageResourceName = "DepartmentNameRequired")]
        public string DepartmentName { get; set; }
}

When Model validation triggers for this class you will get the exception

Expected behavior

Validator should use error message from resource

Actual behavior

Validator is only checking for ErrorMessage and if null tries to set default error message

Regression?

No response

Known Workarounds

Override AbpModelMetadataProvider and change NormalizeValidationAttrbute function to check for "ErrorMessageResourceName" also not just the ErrorMessage
Example:

protected virtual void NormalizeValidationAttrbute(ValidationAttribute validationAttribute)
        {
            if (validationAttribute.ErrorMessage == null && validationAttribute.ErrorMessageResourceName == null)
            {
                ValidationAttributeHelper.SetDefaultErrorMessage(validationAttribute);
            }
        }

Version

7.x

User Interface

Common (Default)

Database Provider

EF Core (Default)

Tiered or separate authentication server

None (Default)

Operation System

Windows (Default)

Other information

No response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants