Skip to content

[BUG] NextLinkOperationImplementation uses AOT incompatible BinaryData APIs #44127

Closed
@eerhardt

Description

@eerhardt

Library name and version

Azure.Monitor.OpenTelemetry.Exporter 1.3.0-beta.2

Describe the bug

NextLinkOperationImplementation is causing AOT warnings in the following code:

var data = new BinaryData(new { version = RehydrationTokenVersion, id = operationId, requestMethod = requestMethod.ToString(), initialUri = startRequestUri.AbsoluteUri, nextRequestUri, headerSource, lastKnownLocation, finalStateVia });

var lroDetails = ModelReaderWriter.Write(rehydrationToken!, ModelReaderWriterOptions.Json).ToObjectFromJson<Dictionary<string, string>>();

NOTE: if you use 1.3.0-beta.1 you don't get any warnings. This is new in 1.3.0-beta.2.

I believe the warnings were introduced in #42686.

@m-redding @TimothyMothra - do you know why these warnings aren't being caught by 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?

Expected behavior

The above app shouldn't produce any AOT warnings. See also #35572 which fixed the warnings initially.

Actual behavior

It produces the following warnings:

ILC : Trim analysis warning IL2026: System.BinaryData.BinaryData(Object,JsonSerializerOptions,Type): Using member 'System.Text.Json.JsonSerializer.SerializeToUtf8Bytes(Object,Type,JsonSerializerOptions)' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. JSON serialization and deserialization might require types that cannot be statically analyzed. Use the overload that takes a JsonTypeInfo orJsonSerializerContext, or make sure all of the required types are preserved. [C:\Users\eerhardt\source\repos\ConsoleApp123\ConsoleApp123\ConsoleApp123.csproj]
ILC : AOT analysis warning IL3050: System.BinaryData.BinaryData(Object,JsonSerializerOptions,Type): Using member 'System.Text.Json.JsonSerializer.SerializeToUtf8Bytes(Object,Type,JsonSerializerOptions)' which has 'RequiresDynamicCodeAttribute' can break functionality when AOT compiling. JSON serialization and deserialization might require types that cannot be statically analyzed and might need runtime code generation. Use System.Text.Json source generation for native AOT applications. [C:\Users\eerhardt\source\repos\ConsoleApp123\ConsoleApp123\ConsoleApp123.csproj]
ILC : Trim analysis warning IL2026: System.BinaryData.ToObjectFromJson<T>(JsonSerializerOptions): Using member 'System.Text.Json.JsonSerializer.Deserialize(ReadOnlySpan`1<Byte>,Type,JsonSerializerOptions)' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. JSON serialization and deserialization might require types that cannot be statically analyzed. Use the overload that takes a JsonTypeInfo or JsonSerializerContext, or make sure all of the required types are preserved. [C:\Users\eerhardt\source\repos\ConsoleApp123\ConsoleApp123\ConsoleApp123.csproj]
ILC : AOT analysis warning IL3050: System.BinaryData.ToObjectFromJson<T>(JsonSerializerOptions): Using member 'System.Text.Json.JsonSerializer.Deserialize(ReadOnlySpan`1<Byte>,Type,JsonSerializerOptions)' which has 'RequiresDynamicCodeAttribute' can break functionality when AOT compiling. JSON serialization and deserialization might require types that cannot be statically analyzed and might need runtime code generation. Use System.Text.Json source generation for native AOT applications. [C:\Users\eerhardt\source\repos\ConsoleApp123\ConsoleApp123\ConsoleApp123.csproj]

Reproduction Steps

dotnet publish the following project

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net8.0</TargetFramework>
    <ImplicitUsings>enable</ImplicitUsings>
    <Nullable>enable</Nullable>
    <PublishAot>true</PublishAot>
    <TrimmerSingleWarn>false</TrimmerSingleWarn>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Azure.Monitor.OpenTelemetry.Exporter" Version="1.3.0-beta.2" />
    <!-- Analyze the whole assembly -->
    <TrimmerRootAssembly Include="Azure.Monitor.OpenTelemetry.Exporter" />
  </ItemGroup>
</Project>

Environment

No response

Metadata

Metadata

Assignees

Labels

Azure.CoreClientThis issue is related to a non-management package

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions