Annotating libraries with small number of warnings to be AOT safe (#72108)
authorLakshan Fernando <lakshanf@microsoft.com>
Fri, 15 Jul 2022 11:01:25 +0000 (04:01 -0700)
committerGitHub <noreply@github.com>
Fri, 15 Jul 2022 11:01:25 +0000 (04:01 -0700)
* Annotating librries with small number of warnings to be AOT safe

* FB

* Fix RR linux arm64 failure and remove ComponentModel annotation

eng/pipelines/runtime-extra-platforms-other.yml
src/libraries/System.Reflection.DispatchProxy/ref/System.Reflection.DispatchProxy.cs
src/libraries/System.Reflection.DispatchProxy/src/System.Reflection.DispatchProxy.csproj
src/libraries/System.Reflection.DispatchProxy/src/System/Reflection/DispatchProxy.cs
src/libraries/System.Reflection.DispatchProxy/src/System/Reflection/DispatchProxyGenerator.cs
src/libraries/tests.proj

index e25d3c8..16ffc6a 100644 (file)
@@ -85,6 +85,7 @@ jobs:
     - windows_x64
     - windows_arm64
     - Linux_x64
+    - Linux_arm64
     jobParameters:
       testGroup: innerloop
       isSingleFile: true
index 82e762d..07bf6ea 100644 (file)
@@ -9,6 +9,7 @@ namespace System.Reflection
     public abstract partial class DispatchProxy
     {
         protected DispatchProxy() { }
+        [System.Diagnostics.CodeAnalysis.RequiresDynamicCodeAttribute("Creating a proxy instance requires generating code at runtime")]
         public static T Create<[System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembersAttribute(System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.All)]  T, [System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembersAttribute(System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)] TProxy>() where TProxy : System.Reflection.DispatchProxy { throw null; }
         protected abstract object? Invoke(System.Reflection.MethodInfo? targetMethod, object?[]? args);
     }
index 45608a8..231c1b9 100644 (file)
@@ -2,6 +2,7 @@
   <PropertyGroup>
     <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
     <TargetFramework>$(NetCoreAppCurrent)</TargetFramework>
+    <EnableAOTAnalyzer>true</EnableAOTAnalyzer>    
   </PropertyGroup>
   <ItemGroup>
     <Compile Include="System\Reflection\DispatchProxy.cs" />
index dbfea73..9a971cb 100644 (file)
@@ -33,6 +33,7 @@ namespace System.Reflection
         /// <returns>An object instance that implements <typeparamref name="T"/>.</returns>
         /// <exception cref="System.ArgumentException"><typeparamref name="T"/> is a class,
         /// or <typeparamref name="TProxy"/> is sealed or does not have a parameterless constructor</exception>
+        [RequiresDynamicCode("Creating a proxy instance requires generating code at runtime")]
         public static T Create<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] T, [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)] TProxy>()
             where TProxy : DispatchProxy
         {
index c779ad0..2f496aa 100644 (file)
@@ -59,6 +59,7 @@ namespace System.Reflection
             typeof(MethodInfo).GetMethod("MakeGenericMethod", new Type[] { typeof(Type[]) })!;
 
         // Returns a new instance of a proxy the derives from 'baseType' and implements 'interfaceType'
+        [RequiresDynamicCode("Defining a dynamic assembly requires generating code at runtime")]
         internal static object CreateProxyInstance(
             [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)] Type baseType,
             [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] Type interfaceType)
@@ -113,6 +114,7 @@ namespace System.Reflection
             private readonly HashSet<string> _ignoresAccessAssemblyNames = new HashSet<string>();
             private ConstructorInfo? _ignoresAccessChecksToAttributeConstructor;
 
+            [RequiresDynamicCode("Defining a dynamic assembly requires generating code at runtime")]
             public ProxyAssembly(AssemblyLoadContext alc)
             {
                 string name;
index bc5fe0d..98c38d1 100644 (file)
                       Condition="'$(TargetOS)' == 'linux'" />
     <ProjectExclusions Include="$(MSBuildThisFileDirectory)System.Threading.Tasks.Dataflow\tests\System.Threading.Tasks.Dataflow.Tests.csproj"
                       Condition="'$(TargetOS)' == 'linux'" />
+    <ProjectExclusions Include="$(MSBuildThisFileDirectory)System.Numerics.Vectors\tests\System.Numerics.Vectors.Tests.csproj"
+                      Condition="'$(TargetOS)' == 'linux'" />
+    <ProjectExclusions Include="$(MSBuildThisFileDirectory)System.Linq.Expressions\tests\System.Linq.Expressions.Tests.csproj"
+                      Condition="'$(TargetOS)' == 'linux' and '$(TargetArchitecture)' == 'arm64'" />
     <ProjectExclusions Include="$(MSBuildThisFileDirectory)System.Net.NameResolution\tests\FunctionalTests\System.Net.NameResolution.Functional.Tests.csproj"
                       Condition="'$(TargetOS)' == 'windows'"/>