Skip to content
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

[NUnitLite] fix many warnings #9959

Merged
merged 1 commit into from
Mar 25, 2025
Merged

Conversation

jonathanpeppers
Copy link
Member

This project had many warnings similar to 18af3ac:

src\Xamarin.Android.NUnitLite\Gui\Instrumentations\TestSuiteInstrumentation.cs(93,5):
warning CA1416: This call site is reachable on all platforms. 'Bundle.PutInt(string?, int)' is only supported on: 'Android' 21.0 and later. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1416)

Basically, every call to an Android API emits this warning.

This analyzer relies on AssemblyInfo.cs to determine the $(SupportedOSPlatformVersion) value. $(GenerateAssemblyInfo)=false appears to break this analyzer!

Since src-ThirdParty\NUnitLite\AssemblyInfo.cs sets some of these values, we can opt out of specifically:

<GenerateAssemblyCompanyAttribute>false</GenerateAssemblyCompanyAttribute>
<GenerateAssemblyConfigurationAttribute>false</GenerateAssemblyConfigurationAttribute>
<GenerateAssemblyProductAttribute>false</GenerateAssemblyProductAttribute>
<GenerateAssemblyTitleAttribute>false</GenerateAssemblyTitleAttribute>
<GenerateAssemblyVersionAttribute>false</GenerateAssemblyVersionAttribute>
<GenerateAssemblyFileVersionAttribute>false</GenerateAssemblyFileVersionAttribute>

And then the CA1416 warnings go away.

I also fixed some trimmer warnings:

src-ThirdParty\NUnitLite\Api\ExpectedExceptionData.cs(130,36): warning IL2070: 'this' argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicMethods', 'DynamicallyAccessedMemberTypes.NonPublicMethods' in call to 'System.Type.GetMethod(String, BindingFlags, Binder, Type[], ParameterModifier[])'. The parameter 'fixtureType' of method 'NUnit.Framework.Api.ExpectedExceptionData.GetExceptionHandler(Type)' does not have matching annotations. The source value must declare at least the same requirements as those declared on the target location it is assigned to.
src-ThirdParty\NUnitLite\Constraints\XmlSerializableConstraint.cs(56,30): warning IL2026: Using member 'System.Xml.Serialization.XmlSerializer.XmlSerializer(Type)' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. Members from serialized types may be trimmed if not referenced directly.
src-ThirdParty\NUnitLite\Constraints\XmlSerializableConstraint.cs(56,30): warning IL3050: Using member 'System.Xml.Serialization.XmlSerializer.XmlSerializer(Type)' which has 'RequiresDynamicCodeAttribute' can break functionality when AOT compiling. XML serializer relies on dynamic code generation which is not available with Ahead of Time compilation.
src-ThirdParty\NUnitLite\ListMapper.cs(57,29): warning IL2075: 'this' argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicProperties', 'DynamicallyAccessedMemberTypes.NonPublicProperties' in call to 'System.Type.GetProperty(String, BindingFlags)'. The return value of method 'System.Object.GetType()' does not have matching annotations. The source value must declare at least the same requirements as those declared on the target location it is assigned to.

Note that I could simply remove ListMapper.cs, as it is not used.

I did not fix all of the trimmer warnings, as there are so many more.

This project had many warnings similar to 18af3ac:

    src\Xamarin.Android.NUnitLite\Gui\Instrumentations\TestSuiteInstrumentation.cs(93,5):
    warning CA1416: This call site is reachable on all platforms. 'Bundle.PutInt(string?, int)' is only supported on: 'Android' 21.0 and later. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1416)

Basically, every call to an Android API emits this warning.

This analyzer relies on `AssemblyInfo.cs` to determine the
`$(SupportedOSPlatformVersion)` value. `$(GenerateAssemblyInfo)=false`
appears to break this analyzer!

Since `src-ThirdParty\NUnitLite\AssemblyInfo.cs` sets some of these
values, we can opt out of specifically:

    <GenerateAssemblyCompanyAttribute>false</GenerateAssemblyCompanyAttribute>
    <GenerateAssemblyConfigurationAttribute>false</GenerateAssemblyConfigurationAttribute>
    <GenerateAssemblyProductAttribute>false</GenerateAssemblyProductAttribute>
    <GenerateAssemblyTitleAttribute>false</GenerateAssemblyTitleAttribute>
    <GenerateAssemblyVersionAttribute>false</GenerateAssemblyVersionAttribute>
    <GenerateAssemblyFileVersionAttribute>false</GenerateAssemblyFileVersionAttribute>

And then the `CA1416` warnings go away.

I also fixed some trimmer warnings:

    src-ThirdParty\NUnitLite\Api\ExpectedExceptionData.cs(130,36): warning IL2070: 'this' argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicMethods', 'DynamicallyAccessedMemberTypes.NonPublicMethods' in call to 'System.Type.GetMethod(String, BindingFlags, Binder, Type[], ParameterModifier[])'. The parameter 'fixtureType' of method 'NUnit.Framework.Api.ExpectedExceptionData.GetExceptionHandler(Type)' does not have matching annotations. The source value must declare at least the same requirements as those declared on the target location it is assigned to.
    src-ThirdParty\NUnitLite\Constraints\XmlSerializableConstraint.cs(56,30): warning IL2026: Using member 'System.Xml.Serialization.XmlSerializer.XmlSerializer(Type)' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. Members from serialized types may be trimmed if not referenced directly.
    src-ThirdParty\NUnitLite\Constraints\XmlSerializableConstraint.cs(56,30): warning IL3050: Using member 'System.Xml.Serialization.XmlSerializer.XmlSerializer(Type)' which has 'RequiresDynamicCodeAttribute' can break functionality when AOT compiling. XML serializer relies on dynamic code generation which is not available with Ahead of Time compilation.
    src-ThirdParty\NUnitLite\ListMapper.cs(57,29): warning IL2075: 'this' argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicProperties', 'DynamicallyAccessedMemberTypes.NonPublicProperties' in call to 'System.Type.GetProperty(String, BindingFlags)'. The return value of method 'System.Object.GetType()' does not have matching annotations. The source value must declare at least the same requirements as those declared on the target location it is assigned to.

Note that I could simply remove `ListMapper.cs`, as it is not used.

I did not fix *all* of the trimmer warnings, as there are so many more.
Copy link
Contributor

@dellis1972 dellis1972 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks ok, lots of build failures thought .... 🤔

@jonathanpeppers
Copy link
Member Author

I think MAUI Integration might be generally broken on their end:

C:\Users\cloudtest\.nuget\packages\microsoft.dotnet.arcade.sdk\10.0.0-beta.25164.6\tools\RepositoryValidation.proj(33,5): error MSB4018: The "Microsoft.DotNet.Arcade.Sdk.GetLicenseFilePath" task failed unexpectedly.
C:\Users\cloudtest\.nuget\packages\microsoft.dotnet.arcade.sdk\10.0.0-beta.25164.6\tools\RepositoryValidation.proj(33,5): error MSB4018: System.IO.FileNotFoundException: Could not load file or assembly 'System.Runtime, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified.

I reran the others.

@jonathanpeppers jonathanpeppers merged commit 1ff5658 into main Mar 25, 2025
56 of 58 checks passed
@jonathanpeppers jonathanpeppers deleted the dev/peppers/nunitwarnings branch March 25, 2025 14:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants