Skip to content

Make Azure.ResourceManager AOT-compatible #50129

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

Merged
merged 1 commit into from
Jul 10, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -8,6 +8,7 @@
using System.Text.Json;
using Azure.Core;
using Azure.ResourceManager.Resources;
using Azure.ResourceManager;

namespace Azure.ResourceManager
{
@@ -47,12 +48,13 @@ public void SetApiVersionsFromProfile(AzureStackProfile profile)
var assembly = Assembly.GetExecutingAssembly();
using (Stream stream = assembly.GetManifestResourceStream(profile.GetManifestName()))
{
var allProfile = BinaryData.FromStream(stream).ToObjectFromJson<Dictionary<string, Dictionary<string, object>>>();
var span = BinaryData.FromStream(stream).ToMemory().Span;
var allProfile = JsonSerializer.Deserialize<Dictionary<string, Dictionary<string, JsonElement>>>(span, ArmClientOptionsJsonContext.Default.DictionaryStringDictionaryStringJsonElement);
var armProfile = allProfile["resource-manager"];
foreach (var keyValuePair in armProfile)
{
var namespaceName = keyValuePair.Key;
var element = (JsonElement)keyValuePair.Value;
var element = keyValuePair.Value;

foreach (var apiVersionProperty in element.EnumerateObject())
{
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using System.Collections.Generic;
using System.Text.Json;
using System.Text.Json.Serialization;

namespace Azure.ResourceManager
{
[JsonSourceGenerationOptions(WriteIndented = false)]
[JsonSerializable(typeof(Dictionary<string, Dictionary<string, JsonElement>>))]
internal partial class ArmClientOptionsJsonContext : JsonSerializerContext
{
}
}
Original file line number Diff line number Diff line change
@@ -77,6 +77,6 @@ public override int GetHashCode()
}

/// <inheritdoc />
public override string ToString() => JsonSerializer.Serialize(this);
public override string ToString() => JsonSerializer.Serialize(this, ArmEnvironmentJsonContext.Default.ArmEnvironment);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using System.Text.Json.Serialization;

namespace Azure.ResourceManager
{
[JsonSourceGenerationOptions(WriteIndented = false)]
[JsonSerializable(typeof(ArmEnvironment))]
internal partial class ArmEnvironmentJsonContext : JsonSerializerContext
{
}
}
Original file line number Diff line number Diff line change
@@ -9,6 +9,7 @@
<PackageTags>azure;management;resource</PackageTags>
<DisableEnhancedAnalysis>true</DisableEnhancedAnalysis>
<UseDefaultNamespaceAndOutputFolder>false</UseDefaultNamespaceAndOutputFolder>
<IsAotCompatible Condition="$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net7.0'))">true</IsAotCompatible>
</PropertyGroup>

<ItemGroup>
Original file line number Diff line number Diff line change
@@ -11,6 +11,7 @@
using System.Text.Json;
using System.Text.Json.Serialization;
using Azure.Core;
using Azure.ResourceManager.Models;

[assembly: CodeGenSuppressType("ManagedServiceIdentity")]
namespace Azure.ResourceManager.Models