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

Native AoT warning from AWSSDK.Core #3173

Open
martincostello opened this issue Feb 5, 2024 · 2 comments
Open

Native AoT warning from AWSSDK.Core #3173

martincostello opened this issue Feb 5, 2024 · 2 comments
Labels
bug This issue is a bug. module/sdk-core p1 This is a high priority issue queued

Comments

@martincostello
Copy link
Contributor

Describe the bug

Doing some testing on an application to see what changes need making for it to be published using native AoT, I observed the following warning during dotnet publish:

C:\codebuild\tmp\output\src3970990199\src\aws-sdk-net\sdk\src\Core\Amazon.Runtime\ConstantClass.cs(84): Trim analysis warning IL2072: Amazon.Runtime.ConstantClass.Intern(): 'type' argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicFields' in call to 'Amazon.Runtime.ConstantClass.LoadFields(Type)'. 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.

Expected Behavior

No trim warnings are emitted from trim analysis of the AWSSDK.Core assembly.

Current Behavior

An IL2072 warning is emitted due to the use of this.GetType() here:

LoadFields(this.GetType());

Reproduction Steps

I'm not sure what specifically my application does that triggers this code path, but you can see by tracing the code that the caller does not provide the guarantees required of the LoadFields() method.

Possible Solution

Annotate/suppress the code as-appropriate to safely resolve the warning and have the code work as expected at runtime in an application compiled for native AoT.

Additional Information/Context

No response

AWS .NET SDK and/or Package version used

AWSSDK.Core 3.7.302.6

Targeted .NET Platform

.NET 8

Operating System and version

Windows 11

@martincostello martincostello added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Feb 5, 2024
@normj
Copy link
Member

normj commented Feb 7, 2024

Odd that didn't show before. I'll take a look to see what is going on.

@bhoradc bhoradc added module/sdk-core p3 This is a minor priority issue and removed needs-triage This issue or PR still needs to be triaged. labels Feb 22, 2024
@beeradmoore
Copy link

Also getting this issue with AWSSDK.Core 3.7.302.20 targeting linux-x64 (building from macOS-x64)

I was originally getting

/.nuget/packages/awssdk.core/3.7.302.20/lib/net8.0/AWSSDK.Core.dll : warning IL2104: Assembly 'AWSSDK.Core' produced trim warnings. For more information see https://aka.ms/dotnet-illink/libraries

but then adding <TrimmerSingleWarn>false</TrimmerSingleWarn> changed it to,

C:\codebuild\tmp\output\src3049721001\src\aws-sdk-net\sdk\src\Core\Amazon.Runtime\ConstantClass.cs(84,17): Trim analysis warning IL2072: Amazon.Runtime.ConstantClass.Intern(): 'type' argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicFields' in call to 'Amazon.Runtime.ConstantClass.LoadFields(Type)'. 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.

I can make a full reproduciton of library and show my testing if needed.

My library targets just net8.0 and I am using the following AWS nugets:

  • AWSSDK.Core (3.7.302.20)
  • AWSSDK.SecretsManager" (3.7.302.34)
  • AWSSDK.SecurityToken (3.7.300.60)
  • AWSSDK.SimpleSystemsManagement (3.7.303.8)
  • Amazon.Lambda.Core (2.2.0)

Doing a brute force of removing nugets (and erroring code) I can narrow it down to using AWSSDK.SimpleSystemsManagement.

Within my code itself I was able to narrow it down to these lines

var simpleSystemsManagementClient = new AmazonSimpleSystemsManagementClient(RegionEndpoint.APSoutheast2);
var getParameterRequest = new GetParameterRequest()
{
    Name = "some/thing",
    WithDecryption = true,
};
var getParameterResponse = await simpleSystemsManagementClient.GetParameterAsync(getParameterRequest);

If I remove the call to GetParameterAsync the problem goes away.

I also added

Console.WriteLine(simpleSystemsManagementClient);
Console.WriteLine(getParameterRequest);

assuming I was linking away the problem from unused code.

I've seen that we should not be using rd.xml, and as expected it didn't help.

<?xml version="1.0" encoding="utf-8"?>
<Directives xmlns="http://schemas.microsoft.com/netfx/2013/01/metadata">
    <Application>
        <Assembly Name="AWSSDK.Core" Dynamic="Required All"></Assembly>
        <Assembly Name="AWSSDK.SecretsManager" Dynamic="Required All"></Assembly>
        <Assembly Name="AWSSDK.SecurityToken" Dynamic="Required All"></Assembly>
        <Assembly Name="AWSSDK.SimpleSystemsManagement" Dynamic="Required All"></Assembly>
        <Assembly Name="Amazon.Lambda.Core" Dynamic="Required All"></Assembly>
    </Application>
</Directives>

Elsewhere I've seen that using <TrimMode>partial</TrimMode> and then only trimming your own assembly with <TrimmableAssembly Include="MyLibrary" /> should do the trick but that may be for the consuming app.

From that above link I followed through to the benchmarking samples which have us adding <TrimmerRootAssembly Include="AWSSDK.Core" />. This did nothing adding to my library itself, adding it to the test project made the warning explode into many warnings.

ILLink : Trim analysis warning IL2026: AWSSDK.Core: Using member 'Amazon.Runtime.Internal.Util.InternalLog4netLogger.levelType' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. SDK logging to Log4net is not supported when trimming is enabled. [MyTestProject.csproj]
ILLink : Trim analysis warning IL2026: AWSSDK.Core: Using member 'Amazon.Runtime.Internal.ClientContext.SERVICE_MOBILE_ANALYTICS_KEY' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. ClientContext has not been updated to support producing JSON using source generators. For requests that need client context JSON the JSON must be created manually. [MyTestProject.csproj]
ILLink : Trim analysis warning IL2026: AWSSDK.Core: Using member 'Amazon.Runtime.Internal.Util.InternalLog4netLogger.getLoggerWithTypeMethod' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. SDK logging to Log4net is not supported when trimming is enabled. [MyTestProject.csproj]
ILLink : Trim analysis warning IL2026: AWSSDK.Core: Using member 'Amazon.Runtime.Internal.Util.InternalLog4netLogger.debugLevelPropertyValue' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. SDK logging to Log4net is not supported when trimming is enabled. [MyTestProject.csproj]
ILLink : Trim analysis warning IL2026: AWSSDK.Core: Using member 'Amazon.Runtime.Internal.ClientContext.SERVICE_MOBILE_ANALYTICS_APP_ID_KEY' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. ClientContext has not been updated to support producing JSON using source generators. For requests that need client context JSON the JSON must be created manually. [MyTestProject.csproj]
ILLink : Trim analysis warning IL2026: AWSSDK.Core: Using member 'Amazon.Runtime.Internal.ClientContext.ENV_MAKE_KEY' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. ClientContext has not been updated to support producing JSON using source generators. For requests that need client context JSON the JSON must be created manually. [MyTestProject.csproj]
ILLink : Trim analysis warning IL2026: AWSSDK.Core: Using member 'Amazon.Runtime.Internal.ClientContext.APP_ID_KEY' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. ClientContext has not been updated to support producing JSON using source generators. For requests that need client context JSON the JSON must be created manually. [MyTestProject.csproj]
ILLink : Trim analysis warning IL2026: AWSSDK.Core: Using member 'Amazon.Runtime.Internal.ClientContext.CLIENT_APP_PACKAGE_NAME_KEY' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. ClientContext has not been updated to support producing JSON using source generators. For requests that need client context JSON the JSON must be created manually. [MyTestProject.csproj]
ILLink : Trim analysis warning IL2026: AWSSDK.Core: Using member 'Amazon.Runtime.Internal.ClientContext.ENV_PLATFORM_VERSION_KEY' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. ClientContext has not been updated to support producing JSON using source generators. For requests that need client context JSON the JSON must be created manually. [MyTestProject.csproj]
ILLink : Trim analysis warning IL2026: AWSSDK.Core: Using member 'Amazon.Runtime.Internal.Util.InternalLog4netLogger.logMethod' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. SDK logging to Log4net is not supported when trimming is enabled. [MyTestProject.csproj]
ILLink : Trim analysis warning IL2026: AWSSDK.Core: Using member 'Amazon.Runtime.Internal.Util.InternalLog4netLogger.loggerType' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. SDK logging to Log4net is not supported when trimming is enabled. [MyTestProject.csproj]
ILLink : Trim analysis warning IL2026: AWSSDK.Core: Using member 'Amazon.Runtime.Internal.ClientContext.CLIENT_ID_CACHE_FILENAME' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. ClientContext has not been updated to support producing JSON using source generators. For requests that need client context JSON the JSON must be created manually. [MyTestProject.csproj]
ILLink : Trim analysis warning IL2026: AWSSDK.Core: Using member 'Amazon.Runtime.Internal.ClientContext.CLIENT_APP_VERSION_NAME_KEY' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. ClientContext has not been updated to support producing JSON using source generators. For requests that need client context JSON the JSON must be created manually. [MyTestProject.csproj]
ILLink : Trim analysis warning IL2026: AWSSDK.Core: Using member 'Amazon.Runtime.Internal.ClientContext.ENV_KEY' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. ClientContext has not been updated to support producing JSON using source generators. For requests that need client context JSON the JSON must be created manually. [MyTestProject.csproj]
ILLink : Trim analysis warning IL2026: AWSSDK.Core: Using member 'Amazon.Runtime.Internal.Util.InternalLog4netLogger.infoLevelPropertyValue' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. SDK logging to Log4net is not supported when trimming is enabled. [MyTestProject.csproj]
ILLink : Trim analysis warning IL2026: AWSSDK.Core: Using member 'Amazon.Runtime.Internal.Util.InternalLog4netLogger.logMangerType' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. SDK logging to Log4net is not supported when trimming is enabled. [MyTestProject.csproj]
ILLink : Trim analysis warning IL2026: AWSSDK.Core: Using member 'Amazon.Runtime.Internal.ClientContext.SERVICES_KEY' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. ClientContext has not been updated to support producing JSON using source generators. For requests that need client context JSON the JSON must be created manually. [MyTestProject.csproj]
ILLink : Trim analysis warning IL2026: AWSSDK.Core: Using member 'Amazon.Runtime.Internal.ClientContext.CUSTOM_KEY' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. ClientContext has not been updated to support producing JSON using source generators. For requests that need client context JSON the JSON must be created manually. [MyTestProject.csproj]
ILLink : Trim analysis warning IL2026: AWSSDK.Core: Using member 'Amazon.Runtime.Internal.ClientContext.CLIENT_APP_TITLE_KEY' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. ClientContext has not been updated to support producing JSON using source generators. For requests that need client context JSON the JSON must be created manually. [MyTestProject.csproj]
ILLink : Trim analysis warning IL2026: AWSSDK.Core: Using member 'Amazon.Runtime.Internal.ClientContext.ENV_MODEL_KEY' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. ClientContext has not been updated to support producing JSON using source generators. For requests that need client context JSON the JSON must be created manually. [MyTestProject.csproj]
ILLink : Trim analysis warning IL2026: AWSSDK.Core: Using member 'Amazon.Runtime.Internal.ClientContext._lock' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. ClientContext has not been updated to support producing JSON using source generators. For requests that need client context JSON the JSON must be created manually. [MyTestProject.csproj]
ILLink : Trim analysis warning IL2026: AWSSDK.Core: Using member 'Amazon.Runtime.Internal.Util.InternalLog4netLogger.logType' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. SDK logging to Log4net is not supported when trimming is enabled. [MyTestProject.csproj]
ILLink : Trim analysis warning IL2026: AWSSDK.Core: Using member 'Amazon.Runtime.Internal.Util.InternalLog4netLogger.LOCK' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. SDK logging to Log4net is not supported when trimming is enabled. [MyTestProject.csproj]
ILLink : Trim analysis warning IL2026: AWSSDK.Core: Using member 'Amazon.Runtime.Internal.Util.InternalLog4netLogger.errorLevelPropertyValue' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. SDK logging to Log4net is not supported when trimming is enabled. [MyTestProject.csproj]
ILLink : Trim analysis warning IL2026: AWSSDK.Core: Using member 'Amazon.Runtime.Internal.Util.InternalLog4netLogger.systemStringFormatType' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. SDK logging to Log4net is not supported when trimming is enabled. [MyTestProject.csproj]
ILLink : Trim analysis warning IL2026: AWSSDK.Core: Using member 'Amazon.Runtime.Internal.Util.InternalLog4netLogger.loadState' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. SDK logging to Log4net is not supported when trimming is enabled. [MyTestProject.csproj]
ILLink : Trim analysis warning IL2026: AWSSDK.Core: Using member 'Amazon.Runtime.Internal.ClientContext.ENV_LOCALE_KEY' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. ClientContext has not been updated to support producing JSON using source generators. For requests that need client context JSON the JSON must be created manually. [MyTestProject.csproj]
ILLink : Trim analysis warning IL2026: AWSSDK.Core: Using member 'Amazon.Runtime.Internal.ClientContext.ENV_PLATFORM_KEY' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. ClientContext has not been updated to support producing JSON using source generators. For requests that need client context JSON the JSON must be created manually. [MyTestProject.csproj]
ILLink : Trim analysis warning IL2026: AWSSDK.Core: Using member 'Amazon.Runtime.Internal.ClientContext.CLIENT_KEY' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. ClientContext has not been updated to support producing JSON using source generators. For requests that need client context JSON the JSON must be created manually. [MyTestProject.csproj]
ILLink : Trim analysis warning IL2026: AWSSDK.Core: Using member 'Amazon.Runtime.Internal.ClientContext.CLIENT_ID_KEY' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. ClientContext has not been updated to support producing JSON using source generators. For requests that need client context JSON the JSON must be created manually. [MyTestProject.csproj]
ILLink : Trim analysis warning IL2026: AWSSDK.Core: Using member 'Amazon.Runtime.Internal.ClientContext.CLIENT_APP_VERSION_CODE_KEY' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. ClientContext has not been updated to support producing JSON using source generators. For requests that need client context JSON the JSON must be created manually. [MyTestProject.csproj]
ILLink : Trim analysis warning IL2026: AWSSDK.Core: Using member 'Amazon.Runtime.Internal.Util.InternalLog4netLogger.isEnabledForMethod' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. SDK logging to Log4net is not supported when trimming is enabled. [MyTestProject.csproj]
C:\codebuild\tmp\output\src3049721001\src\aws-sdk-net\sdk\src\Core\Amazon.Util\AWSSDKUtils.cs(1738,65): Trim analysis warning IL2080: Amazon.Util.AWSSDKUtils.<>c.b__117_0(AWSSDKUtils.IsSetMethodsCacheKey): 'this' argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicMethods', 'DynamicallyAccessedMemberTypes.NonPublicMethods' in call to 'System.Type.GetMethod(String, BindingFlags, Binder, Type[], ParameterModifier[])'. The field 'Amazon.Util.AWSSDKUtils.IsSetMethodsCacheKey.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. [MyTestProject.csproj]
C:\codebuild\tmp\output\src3049721001\src\aws-sdk-net\sdk\src\Core\Amazon.Runtime\ConstantClass.cs(84,17): Trim analysis warning IL2072: Amazon.Runtime.ConstantClass.Intern(): 'type' argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicFields' in call to 'Amazon.Runtime.ConstantClass.LoadFields(Type)'. 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. [MyTestProject.csproj]
C:\codebuild\tmp\output\src3049721001\src\aws-sdk-net\sdk\src\Core\Amazon.Util\Internal\InternalSDKUtils.cs(194,17): Trim analysis warning IL2075: Amazon.Util.Internal.InternalSDKUtils.ApplyValues(Object, IDictionary<String,Object>): 'this' argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicProperties' in call to 'System.Type.GetProperty(String)'. 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. [MyTestProject.csproj]

I am not entierly sure what I am meant to do (or if I can even do anything) to avoid this, or if I am just meant to test test test and ignore the warning for now.

@ashishdhingra ashishdhingra added p1 This is a high priority issue queued and removed p3 This is a minor priority issue needs-review labels Mar 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue is a bug. module/sdk-core p1 This is a high priority issue queued
Projects
None yet
Development

No branches or pull requests

5 participants