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

Microsoft.Extensions.AI.Abstractions is raising trim/AOT warnings #5626

Closed
eerhardt opened this issue Nov 12, 2024 · 1 comment · Fixed by #5627
Closed

Microsoft.Extensions.AI.Abstractions is raising trim/AOT warnings #5626

eerhardt opened this issue Nov 12, 2024 · 1 comment · Fixed by #5627
Assignees

Comments

@eerhardt
Copy link
Member

After #5619 was merged, new warnings are coming from Microsoft.Extensions.AI.Abstractions when trimming/AOT'ing:

    D:\git\extensions\src\Libraries\Microsoft.Extensions.AI.Abstractions\Utilities\AIJsonUtilities.Schema.cs(305): Trim analysis error IL2026: Microsoft.Extensions.AI.AIJsonUtilities.<>c__DisplayClass15_0.<GetJsonSchemaCore>g__TransformSchemaNode|0(JsonSchemaExporterContext,JsonNode): Using member 'System.Text.Json.Nodes.JsonArray.Add<String>(String)' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. Creating JsonValue instances with non-primitive types is not compatible with trimming. It can result in non-primitive types being serialized, which may have their members trimmed. [D:\git\extensions\test\Libraries\Microsoft.Extensions.AotCompatibility.TestApp\Microsoft.Extensions.AotCompatibility.TestApp.csproj]
    D:\git\extensions\src\Libraries\Microsoft.Extensions.AI.Abstractions\Utilities\AIJsonUtilities.Schema.cs(305): AOT analysis error IL3050: Microsoft.Extensions.AI.AIJsonUtilities.<>c__DisplayClass15_0.<GetJsonSchemaCore>g__TransformSchemaNode|0(JsonSchemaExporterContext,JsonNode): Using member 'System.Text.Json.Nodes.JsonArray.Add<String>(String)' which has 'RequiresDynamicCodeAttribute' can break functionality when AOT compiling. Creating JsonValue instances with non-primitive types requires generating code at runtime. [D:\git\extensions\test\Libraries\Microsoft.Extensions.AotCompatibility.TestApp\Microsoft.Extensions.AotCompatibility.TestApp.csproj]

cc @eiriktsarpalis

@eerhardt
Copy link
Member Author

Line 305 is what is causing the warning:

if (required is not JsonArray { } requiredArray || requiredArray.Count != propertiesObj.Count)
{
requiredArray = [.. propertiesObj.Select(prop => prop.Key)];

@agocke - this is a pretty interesting case of how to evade the Roslyn analyzers. Here, there is no explict call to JsonArray.Add<String>(String). But instead, it is using a collection expression, which is calling .Add under the covers. I wonder if the LDM considered this scenario when designing collection expressions (that Analyzers for the .Add calls won't be triggered).

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants