Skip to content

[dotnet-svcutil] defer known types import to resolve IsReference inheritance issue #5810

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

imcarolwang
Copy link
Contributor

Fixes #5769: The DataContract IsReference property was incorrectly set to false for some derived types when known types and inheritance were involved. This led to a mismatch between the imported DataContract type and the referenced type, which caused issues when trying to reuse the referenced types.

Root cause: ImportKnownTypes(typeName) was called immediately after importing each type, which could import derived types as known types before their base types were fully processed, causing inheritance-based IsReference propagation to fail.

Solution: Implement deferred known types import strategy:

  • Add _deferredKnownTypesImport list to collect types requiring known types import
  • Defer known types import until after all main types are imported
  • Process deferred known types after inheritance chains are fully established
  • Ensure IsReference property propagates correctly through inheritance hierarchy

This ensures that inheritance-based property propagation works correctly by processing known types only after the complete type hierarchy is established.

@mconnew
Copy link
Member

mconnew commented Aug 7, 2025

Is this a fix for an issue which also exists on .NET Framework? You've added code that doesn't exist on .NET Framework so I would presume so, but wanted to check first.

@imcarolwang
Copy link
Contributor Author

Is this a fix for an issue which also exists on .NET Framework? You've added code that doesn't exist on .NET Framework so I would presume so, but wanted to check first.

Yes, I think the issue should also exist on .NET Framework. The bug is in the serialization logic, an inheritance timing issue where IsReference property isn't properly set before DataContract equality comparisons occur during referenced assembly type reuse.

The fix has been validated with dotnet-svcutil using the original repro app provided in the reported issue. While I couldn't reproduce it on .NET Framework due to validation challenges:

  • The original repro uses referenced assemblies targeting net8.0, which isn't compatible with .NET Framework
  • Attempts to convert to netstandard2.0 encountered compatibility issues
  • Creating simpler repros proved difficult because the original scenario involves inheritance hierarchies, implicit known type inclusion, and complex relationships between types that are hard to isolate

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ReferencedTypeDoesNotMatch thrown on correct DataContract
2 participants