Azure / azure-sdk-for-net

This repository is for active development of the Azure SDK for .NET. For consumers of the SDK we recommend visiting our public developer docs at https://learn.microsoft.com/dotnet/azure/ or our versioned developer docs at https://azure.github.io/azure-sdk-for-net.
MIT License
5.36k stars 4.75k forks source link

[BUG] Azure.ETagConverter is internal, blocks using System.Text.Json source gen to deserialize objects #35201

Open stephenjust opened 1 year ago

stephenjust commented 1 year ago

Library name and version

Azure.Core 1.28.0

Describe the bug

System.Text.Json's source generators attempt to reference Azure.ETagConverter when you use source generators to create a JsonSerializerContext.

Making Azure.ETagConverter public instead of internal should resolve this issue.

Expected behavior

Azure.ETagConverter should be accessible so that Source Generators create valid code.

Actual behavior

Error CS0122 'ETagConverter' is inaccessible due to its protection level FirewallService System.Text.Json.SourceGeneration\System.Text.Json.SourceGeneration.JsonSourceGenerator\NetworkSecurityGroupTemplateSerializerContext.ETag.g.cs 25 Active

Reproduction Steps

Create a source generator class on .net 6.0 with System.Text.Json 6.0.0:

 [JsonSourceGenerationOptions(PropertyNamingPolicy = JsonKnownNamingPolicy.CamelCase)]
 [JsonSerializable(typeof(SecurityRuleData))]
 internal partial class SecurityRuleDataSerializerContext : JsonSerializerContext
 {
 }

On build, the build will fail due to the reference to Azure.ETagConverter in the generated output.

(This also occurs if you were to include a property of type SecurityRuleData inside some other class. that had a JsonSerializerContext created for it.)

Environment

.NET SDK: Version: 7.0.202 Commit: 6c74320bc3

Runtime Environment: OS Name: Windows OS Version: 10.0.22624 OS Platform: Windows RID: win10-x64 Base Path: C:\Program Files\dotnet\sdk\7.0.202\

Host: Version: 7.0.4 Architecture: x64 Commit: 0a396acafe

.NET SDKs installed: 3.1.426 [C:\Program Files\dotnet\sdk] 5.0.407 [C:\Program Files\dotnet\sdk] 5.0.416 [C:\Program Files\dotnet\sdk] 6.0.202 [C:\Program Files\dotnet\sdk] 6.0.301 [C:\Program Files\dotnet\sdk] 7.0.202 [C:\Program Files\dotnet\sdk]

.NET runtimes installed: Microsoft.AspNetCore.App 6.0.4 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 6.0.15 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 7.0.4 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.NETCore.App 6.0.4 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 6.0.12 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 6.0.15 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 7.0.4 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.WindowsDesktop.App 6.0.4 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 6.0.15 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 7.0.4 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

Other architectures found: x86 [C:\Program Files (x86)\dotnet] registered at [HKLM\SOFTWARE\dotnet\Setup\InstalledVersions\x86\InstallLocation]

Environment variables: Not set

global.json file: Not found

Learn more: https://aka.ms/dotnet/info

Download .NET: https://aka.ms/dotnet/download

jsquire commented 1 year ago

Hi @stephenjust. Thank you for reaching out and we regret that you're experiencing difficulties. Can you provide a bit more context to help me understand the end-to-end scenario for what you're trying to accomplish?

github-actions[bot] commented 1 year ago

Hi @stephenjust. Thank you for opening this issue and giving us the opportunity to assist. To help our team better understand your issue and the details of your scenario please provide a response to the question asked above or the information requested above. This will help us more accurately address your issue.

github-actions[bot] commented 1 year ago

Hi @stephenjust, we're sending this friendly reminder because we haven't heard back from you in 7 days. We need more information about this issue to help address it. Please be sure to give us your input. If we don't hear back from you within 14 days of this comment the issue will be automatically closed. Thank you!

stephenjust commented 1 year ago

We want to enable trimming on our dotnet application that works with ARM models. Reflection based serializers are not supported in trimmed applications, so we tried to use a source generator based serializer. However, the system.text.json source generator does not work on these nuget packages because of their use of an internal converter.

jsquire commented 1 year ago

//cc: @annelo-msft, @JoshLove-msft, @christothes, @AlexanderSher, @KrzysztofCwalina, @tg-msft for discussion.

jsquire commented 1 year ago

Thank you for the additional context, @stephenjust. I've looped in some folks for discussion.

annelo-msft commented 1 year ago

Adding @m-nash, who is working on serialization for .NET Azure SDK libraries.