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

Fix AOT warnings in Azure.Core #44136

Closed
wants to merge 12 commits into from
Closed

Conversation

live1206
Copy link
Member

@live1206 live1206 commented May 19, 2024

Resolves #44127

The AOT warnings now running from https://github.com/Azure/azure-sdk-for-net/blob/main/sdk/monitor/Azure.Monitor.OpenTelemetry.Exporter/tests/Azure.Monitor.OpenTelemetry.Exporter.AotCompatibilityTestApp/test-aot-compat.ps1 are

ILC : Trim analysis warning IL2026: [Azure.Core]Azure.Core.Serialization.DynamicData: Using member 'Azure.Core.Serialization.DynamicData.DynamicDataJsonConverter.DynamicDataJsonConverter()' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. Using DynamicData or DynamicDataConverter is not compatible with trimming due to reflection-based serialization. [C:\src\azure-sdk-for-net\sdk\monitor\Azure.Monitor.OpenTelemetry.Exporter\tests\Azure.Monitor.OpenTelemetry.Exporter.AotCompatibilityTestApp\Azure.Monitor.OpenTelemetry.Exporter.AotCompatibilityTestApp.csproj::TargetFramework=net7.0]
ILC : Trim analysis warning IL2026: [Azure.Core]Azure.Core.Json.MutableJsonDocument: Using member 'Azure.Core.Json.MutableJsonDocument.MutableJsonDocumentConverter.MutableJsonDocumentConverter()' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. Using MutableJsonDocument or MutableJsonDocumentConverter is not compatible with trimming due to reflection-based serialization. [C:\src\azure-sdk-for-net\sdk\monitor\Azure.Monitor.OpenTelemetry.Exporter\tests\Azure.Monitor.OpenTelemetry.Exporter.AotCompatibilityTestApp\Azure.Monitor.OpenTelemetry.Exporter.AotCompatibilityTestApp.csproj::TargetFramework=net7.0]
ILC : AOT analysis warning IL3050: Microsoft.Extensions.DependencyInjection.ServiceLookup.IEnumerableCallSite.ServiceType.get: Using member 'System.Type.MakeGenericType(Type[])' which has 'RequiresDynamicCodeAttribute' can break functionality when AOT compiling. The native code for this instantiation might not be available at runtime. [C:\src\azure-sdk-for-net\sdk\monitor\Azure.Monitor.OpenTelemetry.Exporter\tests\Azure.Monitor.OpenTelemetry.Exporter.AotCompatibilityTestApp\Azure.Monitor.OpenTelemetry.Exporter.AotCompatibilityTestApp.csproj::TargetFramework=net7.0]
/_/src/libraries/System.Linq.Expressions/src/System/Linq/Expressions/BinaryExpression.cs(2239): AOT analysis warning IL3050: System.Linq.Expressions.Expression.GetResultTypeOfShift(Type,Type): Using member 'System.Type.MakeGenericType(Type[])' which has 'RequiresDynamicCodeAttribute' can break functionality when AOT compiling. The native code for this instantiation might not be available at runtime. [C:\src\azure-sdk-for-net\sdk\monitor\Azure.Monitor.OpenTelemetry.Exporter\tests\Azure.Monitor.OpenTelemetry.Exporter.AotCompatibilityTestApp\Azure.Monitor.OpenTelemetry.Exporter.AotCompatibilityTestApp.csproj::TargetFramework=net7.0]
/_/src/libraries/System.Linq.Expressions/src/System/Dynamic/Utils/TypeUtils.cs(28): AOT analysis warning IL3050: System.Dynamic.Utils.TypeUtils.GetNullableType(Type): Using member 'System.Type.MakeGenericType(Type[])' which has 'RequiresDynamicCodeAttribute' can break functionality when AOT compiling. The native code for this instantiation might not be available at runtime. [C:\src\azure-sdk-for-net\sdk\monitor\Azure.Monitor.OpenTelemetry.Exporter\tests\Azure.Monitor.OpenTelemetry.Exporter.AotCompatibilityTestApp\Azure.Monitor.OpenTelemetry.Exporter.AotCompatibilityTestApp.csproj::TargetFramework=net7.0]
Actual warning count is: 5

Other options are:

  • Use JsonElement, which we need to traverse it every time we look up a value, not efficient as JsonObject.
  • Remove NextLinkOperationImplementation.cs from shared core, so that we can use internal members of RehdyrationToken in it directly
  • Make internal members in RehydrationToken public as in Make RehydrationToken members public #43549

@azure-sdk
Copy link
Collaborator

azure-sdk commented May 19, 2024

@live1206
Copy link
Member Author

live1206 commented May 20, 2024

@jsquire
The easiest fix I found is to use JsonNode as in this PR, which only exists in System.Text.Json >= 6.0.0.
After upgrading System.Text.Json and its dependencies System.Text.Encodings.Web to 6.0.0, got below build error, details

sdk/batch/Microsoft.Azure.Batch/src/Microsoft.Azure.Batch.csproj(0,0): Error NU1202: Package System.Text.Encodings.Web 6.0.0 is not compatible with net452 (.NETFramework,Version=v4.5.2). Package System.Text.Encodings.Web 6.0.0 supports:
  - net461 (.NETFramework,Version=v4.6.1)
  - net6.0 (.NETCoreApp,Version=v6.0)
  - netcoreapp3.1 (.NETCoreApp,Version=v3.1)
  - netstandard2.0 (.NETStandard,Version=v2.0)

Will we consider to upgrade the .net framework version for Microsoft.Azure.Batch since it's too old?

eng/Packages.Data.props Outdated Show resolved Hide resolved
@@ -99,10 +99,10 @@
<PackageReference Update="System.Security.Cryptography.ProtectedData" Version="4.7.0" />
<PackageReference Update="System.Threading.Channels" Version="4.7.1" />
<PackageReference Update="System.Threading.Tasks.Extensions" Version="4.5.4" />
<PackageReference Update="System.Text.Json" Version="4.7.2" />
<PackageReference Update="System.Text.Encodings.Web" Version="4.7.2" />
<PackageReference Update="System.Text.Json" Version="6.0.0" />
Copy link
Member

Choose a reason for hiding this comment

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

The v6.x line are confirmed safe with Azure Functions and PowerShell.

@@ -99,10 +99,10 @@
<PackageReference Update="System.Security.Cryptography.ProtectedData" Version="4.7.0" />
<PackageReference Update="System.Threading.Channels" Version="4.7.1" />
<PackageReference Update="System.Threading.Tasks.Extensions" Version="4.5.4" />
<PackageReference Update="System.Text.Json" Version="4.7.2" />
<PackageReference Update="System.Text.Encodings.Web" Version="4.7.2" />
<PackageReference Update="System.Text.Json" Version="6.0.0" />
Copy link
Member

Choose a reason for hiding this comment

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

Let's move to the latest version in the 6.x line rather than 6.0.0 for all of these.

Copy link
Member Author

Choose a reason for hiding this comment

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

Updated System.Text.Json to 6.0.9, 6.0.0 is the only stable version for the other two.

@@ -13,6 +13,7 @@
<ItemGroup>
<PackageReference Include="Azure.Core" />
<PackageReference Include="Microsoft.CSharp" />
<PackageReference Include="System.Text.Json" />
Copy link
Member

Choose a reason for hiding this comment

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

This is most likely needed in the short-term due to the package bump. Please add a comment here documenting that and open an issue to remove this once the next version of Azure.Core is released.

Copy link
Member Author

Choose a reason for hiding this comment

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

Created #44165 for tracking

@@ -35,7 +35,7 @@ void IUtf8JsonSerializable.Write(Utf8JsonWriter writer)
}
DataFactoryLinkedServiceReference? store = default;
DataFactoryElement<string>? secretName = default;
Optional<DataFactoryElement<string>> secretVersion = default;
DataFactoryElement<string>? secretVersion = default;
Copy link
Member

Choose a reason for hiding this comment

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

@JoshLove-msft: Would you offer thoughts on the data factory bits?

@@ -11,6 +11,7 @@
<PackageReference Include="NUnit3TestAdapter" />
<PackageReference Include="Microsoft.NET.Test.Sdk" />
<PackageReference Include="Moq" />
<PackageReference Include="System.Text.Json" />
Copy link
Member

Choose a reason for hiding this comment

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

Same comment as for Experimental. Please track this via comment and issue, as this should be a short-term need.

@@ -122,7 +126,7 @@ internal class NextLinkOperationImplementation : IOperation
finalStateVia = OperationFinalStateVia.Location;
}

string headerSourceStr = GetContentFromRehydrationToken(lroDetails, "headerSource");
string headerSourceStr = GetContentFromRehydrationToken(lroDetails, "headerSource")!;
Copy link
Member

Choose a reason for hiding this comment

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

If we're sure that the outcome here is not null, why is GetContentFromRehydrationToken marked as nullable?

Copy link
Member Author

Choose a reason for hiding this comment

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

Because the nullability depends on the original input, for instance, lastKnownLocation is nullable, we can still get null from RehydrationToken, other fields are not nullable we can ensure they are not null here.

@jsquire
Copy link
Member

jsquire commented May 20, 2024

@jsquire The easiest fix I found is to use JsonNode as in this PR, which only exists in System.Text.Json >= 6.0.0. After upgrading System.Text.Json and its dependencies System.Text.Encodings.Web to 6.0.0, got below build error, details

The Azure.Core team has been discussing/wanting to bump the T2 references to the 6.x line for the framework packages, including System.Text.Json and have done our due diligence to ensure that they won't cause problems with the Functions in-process environment nor PowerShell. This is something that we've agreed that we want to do, but we haven't yet had a forcing function to make it a priority.

We'll need to do a very careful test pass, both CI and Live, for a large portion of the T2 packages across the data and management planes to ensure that the bump doesn't cause regressions. As long as we do that, we should be good with the version bumps.

Will we consider to upgrade the .net framework version for Microsoft.Azure.Batch since it's too old?

No, we cannot change the target frameworks for the T1 package. That said, we shouldn't be bumping the T1 package references. There's a reason why we keep two distinct sets. Let's revert the T1 section back which will ensure that Batch stays stable.

@live1206 live1206 requested a review from vicancy as a code owner May 21, 2024 05:28
@live1206 live1206 requested review from anilba06, gkostal and a team as code owners May 21, 2024 06:51
@live1206 live1206 force-pushed the fix-core-aot branch 2 times, most recently from 38fb07c to cec377b Compare May 21, 2024 09:41
@live1206
Copy link
Member Author

live1206 commented May 21, 2024

After upgrading the packages, there is a version conflict error for Microsoft.Bcl.AsyncInterfaces. Right now Azure.Core is referencing Microsoft.Bcl.AsyncInterfaces.1.1.1, but the global reference is Microsoft.Bcl.AsyncInterfaces.6.0.0. Details

/opt/hostedtoolcache/dotnet/sdk/7.0.101/Microsoft.Common.CurrentVersion.targets(2352,5): Error MSB3277: Found conflicts between different versions of "Microsoft.Bcl.AsyncInterfaces" that could not be resolved.
There was a conflict between "Microsoft.Bcl.AsyncInterfaces, Version=1.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51" and "Microsoft.Bcl.AsyncInterfaces, Version=6.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51".
    "Microsoft.Bcl.AsyncInterfaces, Version=1.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51" was chosen because it was primary and "Microsoft.Bcl.AsyncInterfaces, Version=6.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51" was not.
    References which depend on "Microsoft.Bcl.AsyncInterfaces, Version=1.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51" [/mnt/vss/_work/1/.nuget/packages/microsoft.bcl.asyncinterfaces/1.1.1/ref/netstandard2.1/Microsoft.Bcl.AsyncInterfaces.dll].
        /mnt/vss/_work/1/.nuget/packages/microsoft.bcl.asyncinterfaces/1.1.1/ref/netstandard2.1/Microsoft.Bcl.AsyncInterfaces.dll
          Project file item includes which caused reference "/mnt/vss/_work/1/.nuget/packages/microsoft.bcl.asyncinterfaces/1.1.1/ref/netstandard2.1/Microsoft.Bcl.AsyncInterfaces.dll".
            /mnt/vss/_work/1/.nuget/packages/microsoft.bcl.asyncinterfaces/1.1.1/ref/netstandard2.1/Microsoft.Bcl.AsyncInterfaces.dll
    References which depend on "Microsoft.Bcl.AsyncInterfaces, Version=6.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51" [].
        /mnt/vss/_work/1/s/artifacts/bin/Azure.ResourceManager.Attestation/Debug/netstandard2.0/Azure.ResourceManager.Attestation.dll
          Project file item includes which caused reference "/mnt/vss/_work/1/s/artifacts/bin/Azure.ResourceManager.Attestation/Debug/netstandard2.0/Azure.ResourceManager.Attestation.dll".
            /mnt/vss/_work/1/s/artifacts/bin/Azure.ResourceManager.Attestation/Debug/netstandard2.0/Azure.ResourceManager.Attestation.dll

Feel like this is an issue for Microsoft.Bcl.AsyncInterfaces itself since the same scenario works fine for System.Text.Json.

Tried to release an alpha version of Azure.Core, everything works in #44172

@Azure Azure deleted a comment from azure-pipelines bot May 21, 2024
@Azure Azure deleted a comment from azure-pipelines bot May 21, 2024
@live1206
Copy link
Member Author

After upgrading the packages, there is a version conflict error for Microsoft.Bcl.AsyncInterfaces. Right now Azure.Core is referencing Microsoft.Bcl.AsyncInterfaces.1.1.1, but the global reference is Microsoft.Bcl.AsyncInterfaces.6.0.0. Details

/opt/hostedtoolcache/dotnet/sdk/7.0.101/Microsoft.Common.CurrentVersion.targets(2352,5): Error MSB3277: Found conflicts between different versions of "Microsoft.Bcl.AsyncInterfaces" that could not be resolved.
There was a conflict between "Microsoft.Bcl.AsyncInterfaces, Version=1.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51" and "Microsoft.Bcl.AsyncInterfaces, Version=6.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51".
    "Microsoft.Bcl.AsyncInterfaces, Version=1.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51" was chosen because it was primary and "Microsoft.Bcl.AsyncInterfaces, Version=6.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51" was not.
    References which depend on "Microsoft.Bcl.AsyncInterfaces, Version=1.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51" [/mnt/vss/_work/1/.nuget/packages/microsoft.bcl.asyncinterfaces/1.1.1/ref/netstandard2.1/Microsoft.Bcl.AsyncInterfaces.dll].
        /mnt/vss/_work/1/.nuget/packages/microsoft.bcl.asyncinterfaces/1.1.1/ref/netstandard2.1/Microsoft.Bcl.AsyncInterfaces.dll
          Project file item includes which caused reference "/mnt/vss/_work/1/.nuget/packages/microsoft.bcl.asyncinterfaces/1.1.1/ref/netstandard2.1/Microsoft.Bcl.AsyncInterfaces.dll".
            /mnt/vss/_work/1/.nuget/packages/microsoft.bcl.asyncinterfaces/1.1.1/ref/netstandard2.1/Microsoft.Bcl.AsyncInterfaces.dll
    References which depend on "Microsoft.Bcl.AsyncInterfaces, Version=6.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51" [].
        /mnt/vss/_work/1/s/artifacts/bin/Azure.ResourceManager.Attestation/Debug/netstandard2.0/Azure.ResourceManager.Attestation.dll
          Project file item includes which caused reference "/mnt/vss/_work/1/s/artifacts/bin/Azure.ResourceManager.Attestation/Debug/netstandard2.0/Azure.ResourceManager.Attestation.dll".
            /mnt/vss/_work/1/s/artifacts/bin/Azure.ResourceManager.Attestation/Debug/netstandard2.0/Azure.ResourceManager.Attestation.dll

Feel like this is an issue for Microsoft.Bcl.AsyncInterfaces itself since the same scenario works fine for System.Text.Json.

Tried to release an alpha version of Azure.Core, everything works in #44172

The only option to fix this I found is to upgrade Microsoft.Bcl.AsyncInterfaces to 6.0.0 in #44185. Then release a new version of Azure.Core and apply it in this PR.

@@ -22,6 +22,8 @@

<ItemGroup>
<PackageReference Include="Azure.Core" />
Copy link
Member

Choose a reason for hiding this comment

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

Rather than adding temp references to STJ in these packages, I'd strongly suggest that you use a temporary project reference to Azure.Core to align all of the transitive dependencies.

@live1206
Copy link
Member Author

/azp run net - eventgrid - tests

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@live1206
Copy link
Member Author

/azp run net - eventgrid - tests

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@live1206
Copy link
Member Author

fixing in #44208 instead

@live1206 live1206 closed this May 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BUG] NextLinkOperationImplementation uses AOT incompatible BinaryData APIs
4 participants