dotnet / dotnet/aspnetcore

ValidatableTypeAttribute Fails to Generate Validation Metadata Across Assemblies

Open
#63,626 7 comments 1 reaction 0 assignees View on GitHub
area-minimal feature-validation
Dominant language
C#
Stars
38.4k
Forks
10.9k
Avg merge
2d 6h
Merged PRs (30d)
290

Description

### Is there an existing issue for this?

- [x] I have searched the existing issues

### Describe the bug

When applying the `[ValidatableType]` attribute to a class located in a different assembly than the one invoking `builder.Services.AddValidation()`, the validation metadata for that class is not generated into the `GeneratedValidatableInfoResolver`.

### Expected Behavior

All types annotated with `[ValidatableType]`, regardless of the assembly they reside in, should be included in the generated `GeneratedValidatableInfoResolver`.

### Steps To Reproduce

1. Create a class in Assembly A and annotate it with `[ValidatableType]`.
2. In Assembly B, call `builder.Services.AddValidation()`.
3. Observe that the class from Assembly A is not included in the generated resolver.

### Exceptions (if any)

_No response_

### .NET Version

10.0.100-rc.1.25451.107

### Anything else?

### Proposed Solutions

**Primary Solution:**

Enhance the source generator to scan all referenced assemblies for [ValidatableType] attributes and include them in the generated GeneratedValidatableInfoResolver.

**Alternative Solution:**

Generate a separate ValidatableInfoResolver per assembly. These resolvers could then be manually registered with ValidationOptions to compose a complete validation metadata set.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.