Skip to content

Validation error is returned twice #79

@Lanayx

Description

@Lanayx

Repro:

using System.ComponentModel.DataAnnotations;
using MiniValidation;

class Test {
    [MinLength(3)]
    public string ErrorCode { get; set; }
}

class Program
{
    static void Main(string[] args)
    {
        MiniValidator.TryValidate(
            new Test { ErrorCode = "12" },
            out var errors);
        foreach (var error in errors)
        {
            foreach (var errorMessage in error.Value)
            {
                Console.WriteLine($"Property: {error.Key}, Error: {errorMessage}");
            }
        }
    }
}

Output:

Property: ErrorCode, Error: The field ErrorCode must be a string or array type with a minimum length of '3'.
Property: ErrorCode, Error: The field ErrorCode must be a string or array type with a minimum length of '3'.

The bug is reproduced with both .NET 8 and .NET 9.
MiniValidation version is 0.9.2

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions