-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
Source generator for options validation leads to trimming warnings/errors in AOT #92327
Comments
Tagging subscribers to this area: @dotnet/area-system-componentmodel-dataannotations Issue DetailsDescriptionIf you follow the guide in the docs, you get trimming warnings related to data annotations. In my own program, these warnings lead to errors. Reproduction Steps
Expected behaviorProgram compiles without error and warnings. Actual behaviorYou get a bunch of trimming warnings related to data annotations: /tmp/optionsvalidator/Microsoft.Extensions.Options.SourceGeneration/Microsoft.Extensions.Options.Generators.OptionsValidatorGenerator/Validators.g.cs(50): Trim analysis warning IL2026: SecondValidatorNoNamespace.Validate(String,SecondModelNoNamespace): Using member 'System.ComponentModel.DataAnnotations.ValidationContext.ValidationContext(Object)' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. The Type of instance cannot be statically discovered and the Type's properties can be trimmed. [/tmp/optionsvalidator/optionsvalidator.csproj]
/tmp/optionsvalidator/Microsoft.Extensions.Options.SourceGeneration/Microsoft.Extensions.Options.Generators.OptionsValidatorGenerator/Validators.g.cs(17): Trim analysis warning IL2026: FirstValidatorNoNamespace.Validate(String,FirstModelNoNamespace): Using member 'System.ComponentModel.DataAnnotations.ValidationContext.ValidationContext(Object)' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. The Type of instance cannot be statically discovered and the Type's properties can be trimmed. [/tmp/optionsvalidator/optionsvalidator.csproj]
/tmp/optionsvalidator/Microsoft.Extensions.Options.SourceGeneration/Microsoft.Extensions.Options.Generators.OptionsValidatorGenerator/Validators.g.cs(73): Trim analysis warning IL2026: __OptionValidationStaticInstances.<Validators_g>F1872690B80E3D4EBF0BB4EEFEFFBD255387F31D123553B47D3D3ED7D782424E7____Attributes..cctor(): Using member 'System.ComponentModel.DataAnnotations.MinLengthAttribute.MinLengthAttribute(Int32)' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. Uses reflection to get the 'Count' property on types that don't implement ICollection. This 'Count' property may be trimmed. Ensure it is preserved. [/tmp/optionsvalidator/optionsvalidator.csproj] Regression?No response Known WorkaroundsNo response Configuration
Other informationNo response
|
Did further testing. The functionality seems to work. So the problem is the warnings. |
Tagging subscribers to this area: @dotnet/area-extensions-options Issue DetailsDescriptionIf you follow the guide in the docs, you get trimming warnings related to data annotations. In my own program, these warnings lead to errors. Reproduction Steps
Expected behaviorProgram compiles without error and warnings. Actual behaviorYou get a bunch of trimming warnings related to data annotations: /tmp/optionsvalidator/Microsoft.Extensions.Options.SourceGeneration/Microsoft.Extensions.Options.Generators.OptionsValidatorGenerator/Validators.g.cs(50): Trim analysis warning IL2026: SecondValidatorNoNamespace.Validate(String,SecondModelNoNamespace): Using member 'System.ComponentModel.DataAnnotations.ValidationContext.ValidationContext(Object)' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. The Type of instance cannot be statically discovered and the Type's properties can be trimmed. [/tmp/optionsvalidator/optionsvalidator.csproj]
/tmp/optionsvalidator/Microsoft.Extensions.Options.SourceGeneration/Microsoft.Extensions.Options.Generators.OptionsValidatorGenerator/Validators.g.cs(17): Trim analysis warning IL2026: FirstValidatorNoNamespace.Validate(String,FirstModelNoNamespace): Using member 'System.ComponentModel.DataAnnotations.ValidationContext.ValidationContext(Object)' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. The Type of instance cannot be statically discovered and the Type's properties can be trimmed. [/tmp/optionsvalidator/optionsvalidator.csproj]
/tmp/optionsvalidator/Microsoft.Extensions.Options.SourceGeneration/Microsoft.Extensions.Options.Generators.OptionsValidatorGenerator/Validators.g.cs(73): Trim analysis warning IL2026: __OptionValidationStaticInstances.<Validators_g>F1872690B80E3D4EBF0BB4EEFEFFBD255387F31D123553B47D3D3ED7D782424E7____Attributes..cctor(): Using member 'System.ComponentModel.DataAnnotations.MinLengthAttribute.MinLengthAttribute(Int32)' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. Uses reflection to get the 'Count' property on types that don't implement ICollection. This 'Count' property may be trimmed. Ensure it is preserved. [/tmp/optionsvalidator/optionsvalidator.csproj] Regression?No response Known WorkaroundsNo response Configuration
Other informationNo response
|
Thanks @rstropek. I will look at that. |
@rstropek I am trying the exact steps, but I am getting the warnings:
these are expected and for this specific example which has the Now, I am trying to get the same failures you are getting on the generated code |
@rstropek never mind, I can see the warnings now when publishing. |
@tarekgh Oh, sorry. I mentioned |
Description
If you follow the guide in the docs, you get trimming warnings related to data annotations. In my own program, these warnings lead to errors.
Reproduction Steps
Create a new app:
dotnet new webapiaot
Add NuGet.config:
Add nightly package references in .csproj:
Copy sample code from the docs into your Program.cs
Build app:
dotnet run build
Expected behavior
Program compiles without error and warnings.
Actual behavior
You get a bunch of trimming warnings related to data annotations:
Regression?
No response
Known Workarounds
No response
Configuration
Other information
No response
The text was updated successfully, but these errors were encountered: