Annoating Net.Quic & Net.Security libraries to be AOT safe (#72791)
authorLakshan Fernando <lakshanf@microsoft.com>
Thu, 28 Jul 2022 17:16:37 +0000 (10:16 -0700)
committerGitHub <noreply@github.com>
Thu, 28 Jul 2022 17:16:37 +0000 (10:16 -0700)
* Annoating Net.Quic & Net.Security libraries to be AOT safe

* changing the justification msg as per FB

* workaround for issue 72833

src/libraries/Common/src/System/Net/Http/X509ResourceClient.cs
src/libraries/System.Net.Quic/src/System.Net.Quic.csproj
src/libraries/System.Net.Security/src/System.Net.Security.csproj

index ae6c0a1..ff5a237 100644 (file)
@@ -2,6 +2,7 @@
 // The .NET Foundation licenses this file to you under the MIT license.
 
 using System.Diagnostics;
+using System.Diagnostics.CodeAnalysis;
 using System.IO;
 using System.Reflection;
 using System.Threading;
@@ -97,7 +98,13 @@ namespace System.Net.Http
                     return null;
                 }
 
-                Type taskOfHttpResponseMessageType = typeof(Task<>).MakeGenericType(httpResponseMessageType);
+                // Workaround until https://github.com/dotnet/runtime/issues/72833 is fixed
+                [UnconditionalSuppressMessage("AotAnalysis", "IL3050:RequiresDynamicCode",
+                   Justification = "The type HttpResponseMessage is a reference type")]
+                [return: DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)]
+                static Type GetTaskOfHttpResponseMessageType([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] Type? httpResponseMessageType) => typeof(Task<>).MakeGenericType(httpResponseMessageType!);
+
+                Type taskOfHttpResponseMessageType = GetTaskOfHttpResponseMessageType(httpResponseMessageType);
 
                 // Get the methods on those types.
                 ConstructorInfo? socketsHttpHandlerCtor = socketsHttpHandlerType.GetConstructor(Type.EmptyTypes);
index 4eb9f51..86f1e5c 100644 (file)
@@ -2,6 +2,7 @@
   <PropertyGroup>
     <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
     <TargetFrameworks>$(NetCoreAppCurrent)-windows;$(NetCoreAppCurrent)-Linux;$(NetCoreAppCurrent)-OSX;$(NetCoreAppCurrent)-FreeBSD;$(NetCoreAppCurrent)</TargetFrameworks>
+    <EnableAOTAnalyzer>true</EnableAOTAnalyzer>
   </PropertyGroup>
   <!-- DesignTimeBuild requires all the TargetFramework Derived Properties to not be present in the first property group. -->
   <PropertyGroup>
index eba0ccf..372b716 100644 (file)
@@ -4,6 +4,7 @@
     <TargetFrameworks>$(NetCoreAppCurrent)-windows;$(NetCoreAppCurrent)-Linux;$(NetCoreAppCurrent)-FreeBSD;$(NetCoreAppCurrent)-Android;$(NetCoreAppCurrent)-OSX;$(NetCoreAppCurrent)-iOS;$(NetCoreAppCurrent)-tvOS;$(NetCoreAppCurrent)</TargetFrameworks>
     <!-- This is needed so that code for TlsCipherSuite will have no namespace (causes compile errors) when used within T4 template  -->
     <DefineConstants>$(DefineConstants);PRODUCT</DefineConstants>
+    <EnableAOTAnalyzer>true</EnableAOTAnalyzer>
   </PropertyGroup>
   <!-- DesignTimeBuild requires all the TargetFramework Derived Properties to not be present in the first property group. -->
   <PropertyGroup>