[http-client-csharp] Keep MRW builders for system types referenced by generated serialization - #11398
Conversation
SystemObjectModelProvider instances were unconditionally rejected by ProviderReferenceMapAnalyzer.IsResolvableBuildableProvider, so the MRW context dropped ModelReaderWriterBuildable entries for framework types (e.g. ManagedServiceIdentity, ResponseError, SystemData) that generated serialization code still reads through ModelReaderWriter.Read<T>(..., Context.Default), causing runtime failures. Keep such a provider resolvable when its wrapped SystemType implements IPersistableModel<T> or IJsonModel<T>. Fixes microsoft#11396. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 4e996d84-23b1-4051-b2ba-d0a08d41ca93
commit: |
|
No changes needing a change description found. |
|
Closing this — further investigation shows the premise of #11396 does not hold, and this change would actually regress generated output. Why this fix is wrongMaking EvidenceI classified every buildable-attribute removal across the 156 context files in the Azure SDK regeneration PR (Azure/azure-sdk-for-net#61331). Removals: 154x
Decisive check: of the 154 libraries that lost Counter-evidence that the pruning is precise: ManagedNetworkFabric keeps |
Summary
ProviderReferenceMapAnalyzer.IsResolvableBuildableProvider()rejected everySystemObjectModelProvider, soModelReaderWriterContextDefinitionpruned[ModelReaderWriterBuildable(...)]entries for ARM framework types (ManagedServiceIdentity,ResponseError,SystemData, ...) while generated serialization still deserializes them viaModelReaderWriter.Read<T>(data, options, Context.Default). That path callscontext.GetTypeBuilder(returnType)and threwInvalidOperationException: No ModelReaderWriterTypeBuilder found ...at runtime.Regression from #11288 (
89f388c40).Change
A
SystemObjectModelProvideris now considered resolvable for MRW context generation when its wrappedSystemTypeimplementsIPersistableModel<T>orIJsonModel<T>. ExternalModelProviders and providers removed by the reference map remain excluded.Tests
SystemObjectModelProvidersSupportingMrwRemainBuildable— regression coverage; fails onmainwith the buildable attribute missing, passes with the fix.SystemObjectModelProvidersWithoutMrwSupportAreNotBuildable— negative coverage so non-MRW system types stay excluded.Validation
Microsoft.TypeSpec.Generator.ClientModel.Tests: 1515/1515 passedMicrosoft.TypeSpec.Generator.Tests: 1720/1720 passedFixes #11396.