-
Notifications
You must be signed in to change notification settings - Fork 10.4k
Description
Is there an existing issue for this?
- I have searched the existing issues
Describe the bug
When multiple types with the same name are used (but within a different namespace), the generated output contains errors. This leads in a failing build.
The output will contain duplicate names, causing the error.
Here's an extract of a class Entity
that exists in the Persons
and Pets
namespaces:
if (type == typeof(global::MinApiValidationRepro.Persons.Entity))
{
validatableInfo = CreateEntity();
return true;
}
if (type == typeof(global::MinApiValidationRepro.Pets.Entity))
{
validatableInfo = CreateEntity();
return true;
}
private ValidatableTypeInfo CreateEntity()
{
return new GeneratedValidatableTypeInfo(
type: typeof(global::MinApiValidationRepro.Persons.Entity),
members: [
new GeneratedValidatablePropertyInfo(
containingType: typeof(global::MinApiValidationRepro.Persons.Entity),
propertyType: typeof(int),
name: "Id",
displayName: "Id"
),
new GeneratedValidatablePropertyInfo(
containingType: typeof(global::MinApiValidationRepro.Persons.Entity),
propertyType: typeof(string),
name: "Name",
displayName: "Name"
),
]
);
}
private ValidatableTypeInfo CreateEntity()
{
return new GeneratedValidatableTypeInfo(
type: typeof(global::MinApiValidationRepro.Pets.Entity),
members: [
new GeneratedValidatablePropertyInfo(
containingType: typeof(global::MinApiValidationRepro.Pets.Entity),
propertyType: typeof(int),
name: "Id",
displayName: "Id"
),
new GeneratedValidatablePropertyInfo(
containingType: typeof(global::MinApiValidationRepro.Pets.Entity),
propertyType: typeof(string),
name: "Breed",
displayName: "Breed"
),
]
);
}
Expected Behavior
I expect the build to succeed.
Maybe that the fully qualified type name can be used to generate the code?
Steps To Reproduce
You can checkout the following reproduction, https://github.com/timdeschryver/MinApiValidationRepro.
Try to run a build, which will fail.
The repo also contains the generated files.
Exceptions (if any)
MinApiValidationRepro failed with 1 error(s) (0,9s)
D:\MinApiValidationRepro\Generated\Microsoft.AspNetCore.Http.ValidationsGenerator\Microsoft.AspNetCore.Http.ValidationsGenerator.ValidationsGenerator\ValidatableInfoResolver.g.cs(103,37): error CS0111: Type 'GeneratedValidatableInfoResolver' already defines a member called 'CreateEntity' with the same parameter types
Build failed with 1 error(s) in 3,3s
The build failed. Fix the build errors and run again.
.NET Version
10.0.100-preview.4.25258.110
Anything else?
I really like the addition of this feature 🥳