[Mgmt][CodeGen] Fix KeyNotFoundException in LRO generation when multiple resources share one ResourceData type#59367
Merged
Conversation
…are one ResourceData type Agent-Logs-Url: https://github.com/Azure/azure-sdk-for-net/sessions/8678245a-2488-4c7a-9d5a-be11226713b3 Co-authored-by: haiyuazhang <1924967+haiyuazhang@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix LRO generation crashes with KeyNotFoundException
[Mgmt][CodeGen] Fix KeyNotFoundException in LRO generation when multiple resources share one ResourceData type
May 20, 2026
haiyuazhang
approved these changes
May 26, 2026
live1206
marked this pull request as ready for review
May 26, 2026 02:17
live1206
requested review from
ArcturusZhang,
JoshLove-msft,
jorgerangel-msft,
live1206 and
m-nash
as code owners
May 26, 2026 02:17
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes a crash in the management-plane generator’s LRO handling when multiple ResourceClientProviders share the same ResourceData type by making OperationSourceDict registration symmetric with the lookup behavior in ResourceOperationMethodProvider.BuildLroHandling.
Changes:
- Register an additional fallback
OperationSourceProviderkeyed by the raw data model type when multiple resources share that model type. - Update the existing unit test to assert the new fallback operation source entry is generated.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| eng/packages/http-client-csharp-mgmt/generator/Azure.Generator.Management/src/ManagementOutputLibrary.cs | Adds a raw-data-type fallback entry in ProcessLroMethod when multiple resources match the LRO return model type, preventing OperationSourceDict lookup failures. |
| eng/packages/http-client-csharp-mgmt/generator/Azure.Generator.Management/test/Providers/OperationSourceProviderTests.cs | Updates assertions to expect the additional data-type-keyed fallback operation source alongside the per-resource entries. |
live1206
approved these changes
May 26, 2026
ArcturusZhang
approved these changes
May 28, 2026
mcgallan
pushed a commit
to mcgallan/azure-sdk-for-net
that referenced
this pull request
Jun 11, 2026
…ple resources share one ResourceData type (Azure#59367)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
ResourceOperationMethodProvider.BuildLroHandlingcrashes withKeyNotFoundExceptionwhen N≥2ResourceClientProviders share a singleResourceDatatype and at least one owns an LRO (e.g. Billing role assignment / role definition MPG migration, whereBillingRoleAssignmentDatabacks 6 distinct resources across different parent scopes).Root cause is an asymmetry between populator and reader of
OperationSourceDict:ManagementOutputLibrary.ProcessLroMethod) registers N entries keyed by eachresourceProvider.Type.BuildLroHandlingviaTryGetResourceClientProvider) intentionally bails out (Count != 1) and falls through to the non-resource branch, which looks up the raw data type key — never registered → crash.Changes
ManagementOutputLibrary.ProcessLroMethod— when more than one resource provider matches the LRO return type, additionally register a fallbackOperationSourceProviderkeyed by the raw data type. This mirrorsTryGetResourceClientProvider's "skip wrapping" intent and makes the dictionary symmetric with whatBuildLroHandlingreads in the non-wrap branch.OperationSourceProviderTests.Verify_MultipleResourcesSharingDataModel_GeneratesSeparateOperationSources— updated to assert the new fallback entry (SiteDataOperationSource) is present alongside the two resource-typed entries (count now 3).This is Option A from the issue — the minimal fix matching the existing intent in
TryGetResourceClientProvider. Option B (deterministic resource selection in the reader) is left for a future change if a friendlierArmOperation<TResource>shape is desired.This checklist is used to make sure that common guidelines for a pull request are followed.
General Guidelines
Testing Guidelines
SDK Generation Guidelines
*.csprojandAssemblyInfo.csfiles have been updated with the new version of the SDK.