Skip to content

Bug: Change in behavior with .NET 5 vs .NET 6 in AllowMultiple attributes #63195

@Rutix

Description

@Rutix

Description

We are upgrading our solutions from .NET 5 and .NET 6 and it went well until in one solutions a lot of unittests started failing. It seems that when you use TryValidateObject from System.ComponentModel.DataAnnotations it won't go through all the (custom) validation attributes of the same type when there are multiple on a property. While debugging in .NET 5 you go through the IsValid method as many times as you have added the attribute but in .NET 6 it will only call the IsValid and it seems to be of the last attribute.

Reproduction Steps

I have tried to make an as minimal repo as possible:

.NET 5:
https://github.com/Rutix/ValidationTest/blob/main/ValidationTest.Unittest/UnitTest1.cs

Running this will pass the test.

.NET 6:
https://github.com/Rutix/ValidationTest/blob/net6/ValidationTest.Unittest/UnitTest1.cs

Running this will fail the test.

Expected behavior

The expected behavior (unless i missed a breaking change) would be the behavior which we get in .NET 5.

Actual behavior

IsValid isn't called on all the attributes of the same type.

Regression?

Worked in .NET 5

Known Workarounds

No response

Configuration

No response

Other information

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions