From 1fcbfa6ad64d541a9761f8cdadb9a8c039fcc2d4 Mon Sep 17 00:00:00 2001 From: Carol Wang Date: Mon, 14 Jul 2025 17:16:17 +0800 Subject: [PATCH] [dotnet-svcutil] defer known types import to resolve IsReference inheritance issue --- .../Runtime/Serialization/SchemaImporter.cs | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/dotnet-svcutil/lib/src/FrameworkFork/System.Runtime.Serialization/System/Runtime/Serialization/SchemaImporter.cs b/src/dotnet-svcutil/lib/src/FrameworkFork/System.Runtime.Serialization/System/Runtime/Serialization/SchemaImporter.cs index bbeae2840b9..862adabec05 100644 --- a/src/dotnet-svcutil/lib/src/FrameworkFork/System.Runtime.Serialization/System/Runtime/Serialization/SchemaImporter.cs +++ b/src/dotnet-svcutil/lib/src/FrameworkFork/System.Runtime.Serialization/System/Runtime/Serialization/SchemaImporter.cs @@ -28,6 +28,7 @@ internal class SchemaImporter private SchemaObjectDictionary _schemaObjects; private List _redefineList; private bool _needToImportKnownTypesForObject; + private List _deferredKnownTypesImport; // TODO: [Fx.Tag.SecurityNote(Critical = "Static field used to store serialization schema elements from future versions." @@ -129,6 +130,17 @@ internal void Import() } } ImportKnownTypesForObject(); + + // Import known types for all deferred types after all main types have been imported + if (_deferredKnownTypesImport != null) + { + // Create a copy of the list to avoid collection modification during enumeration + var deferredTypesToProcess = new List(_deferredKnownTypesImport); + foreach (XmlQualifiedName typeName in deferredTypesToProcess) + { + ImportKnownTypes(typeName); + } + } } internal static void CompileSchemaSet(XmlSchemaSet schemaSet) @@ -490,7 +502,11 @@ private DataContract ImportType(XmlSchemaType type, XmlQualifiedName typeName, b ImportTopLevelElement(typeName); ImportDataContractExtension(type, dataContract); ImportGenericInfo(type, dataContract); - ImportKnownTypes(typeName); + + // Defer known types import - add to list for later processing + if (_deferredKnownTypesImport == null) + _deferredKnownTypesImport = new List(); + _deferredKnownTypesImport.Add(typeName); return dataContract; }