Skip to content

Commit 1ff5658

Browse files
[NUnitLite] fix many warnings (#9959)
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.
1 parent 82489d0 commit 1ff5658

File tree

8 files changed

+22
-83
lines changed

8 files changed

+22
-83
lines changed

src-ThirdParty/NUnitLite/Api/ExpectedExceptionData.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
// ***********************************************************************
2323

2424
using System;
25+
using System.Diagnostics.CodeAnalysis;
2526
using System.Reflection;
2627

2728
namespace NUnit.Framework.Api
@@ -123,7 +124,9 @@ public string HandlerName
123124
/// </summary>
124125
/// <param name="fixtureType">The Type of the fixture.</param>
125126
/// <returns>A MethodInfo.</returns>
126-
public MethodInfo GetExceptionHandler(Type fixtureType)
127+
public MethodInfo GetExceptionHandler (
128+
[DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicMethods | DynamicallyAccessedMemberTypes.NonPublicMethods)]
129+
Type fixtureType)
127130
{
128131
if (exceptionHandler == null && handlerName != null)
129132
{

src-ThirdParty/NUnitLite/AssertionHelper.cs

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -350,17 +350,5 @@ static public void Expect<T>(T actual, IResolveConstraint expression, string mes
350350
#endif
351351

352352
#endregion
353-
354-
#region Map
355-
/// <summary>
356-
/// Returns a ListMapper based on a collection.
357-
/// </summary>
358-
/// <param name="original">The original collection</param>
359-
/// <returns></returns>
360-
public ListMapper Map( ICollection original )
361-
{
362-
return new ListMapper( original );
363-
}
364-
#endregion
365353
}
366354
}

src-ThirdParty/NUnitLite/Constraints/ConstraintExpression.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
// ***********************************************************************
2323

2424
using System;
25+
using System.Diagnostics.CodeAnalysis;
2526
using System.Collections;
2627

2728
namespace NUnit.Framework.Constraints
@@ -358,6 +359,8 @@ public UniqueItemsConstraint Unique
358359
/// </summary>
359360
public XmlSerializableConstraint XmlSerializable
360361
{
362+
[RequiresUnreferencedCode ("Uses XmlSerializer")]
363+
[RequiresDynamicCode ("Uses XmlSerializer")]
361364
get { return (XmlSerializableConstraint)this.Append(new XmlSerializableConstraint()); }
362365
}
363366
#endif

src-ThirdParty/NUnitLite/Constraints/ConstraintFactory.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
// ***********************************************************************
2323

2424
using System;
25+
using System.Diagnostics.CodeAnalysis;
2526
using System.Collections;
2627

2728
namespace NUnit.Framework.Constraints
@@ -305,6 +306,8 @@ public UniqueItemsConstraint Unique
305306
/// </summary>
306307
public XmlSerializableConstraint XmlSerializable
307308
{
309+
[RequiresUnreferencedCode ("Uses XmlSerializer")]
310+
[RequiresDynamicCode ("Uses XmlSerializer")]
308311
get { return new XmlSerializableConstraint(); }
309312
}
310313
#endif

src-ThirdParty/NUnitLite/Constraints/XmlSerializableConstraint.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
#if !SILVERLIGHT
2525
using System;
26+
using System.Diagnostics.CodeAnalysis;
2627
using System.IO;
2728
using System.Xml;
2829
using System.Xml.Serialization;
@@ -33,6 +34,8 @@ namespace NUnit.Framework.Constraints
3334
/// XmlSerializableConstraint tests whether
3435
/// an object is serializable in XML format.
3536
/// </summary>
37+
[RequiresUnreferencedCode ("Uses XmlSerializer")]
38+
[RequiresDynamicCode ("Uses XmlSerializer")]
3639
public class XmlSerializableConstraint : Constraint
3740
{
3841
private XmlSerializer serializer;

src-ThirdParty/NUnitLite/Is.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
// ***********************************************************************
2323

2424
using System;
25+
using System.Diagnostics.CodeAnalysis;
2526
using System.Collections;
2627
using NUnit.Framework.Constraints;
2728

@@ -165,6 +166,8 @@ public static UniqueItemsConstraint Unique
165166
/// </summary>
166167
public static XmlSerializableConstraint XmlSerializable
167168
{
169+
[RequiresUnreferencedCode ("Uses XmlSerializer")]
170+
[RequiresDynamicCode ("Uses XmlSerializer")]
168171
get { return new XmlSerializableConstraint(); }
169172
}
170173
#endif

src-ThirdParty/NUnitLite/ListMapper.cs

Lines changed: 0 additions & 69 deletions
This file was deleted.

src/Xamarin.Android.NUnitLite/Xamarin.Android.NUnitLite.NET.csproj

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,12 @@
1515
CS1591: Missing XML comment for publicly visible type or member 'Foo'
1616
-->
1717
<NoWarn>1570;1572;1591;CA1305</NoWarn>
18-
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
18+
<GenerateAssemblyCompanyAttribute>false</GenerateAssemblyCompanyAttribute>
19+
<GenerateAssemblyConfigurationAttribute>false</GenerateAssemblyConfigurationAttribute>
20+
<GenerateAssemblyProductAttribute>false</GenerateAssemblyProductAttribute>
21+
<GenerateAssemblyTitleAttribute>false</GenerateAssemblyTitleAttribute>
22+
<GenerateAssemblyVersionAttribute>false</GenerateAssemblyVersionAttribute>
23+
<GenerateAssemblyFileVersionAttribute>false</GenerateAssemblyFileVersionAttribute>
1924
</PropertyGroup>
2025

2126
<PropertyGroup>

0 commit comments

Comments
 (0)