Skip to content

ReferencedTypeDoesNotMatch thrown on correct DataContract #5769

Open

Description

@BitKFu

Describe the bug
I have a WCF service that uses two DLLs with base types. Once we reference that base types, the data contract will throw the ReferencedTypeDoesNotMatch.

There must be a difference to older versions, where the Reference.cs has been written / even the referenced types are not used and therefore generated as duplicates.

The WSDL File is generated right before creating the service - so I assume that this is correct.

The strange thing this is, that this is only one service that is not working - other WSDL files in our project can be used without any hassle.

To Reproduce
Steps to reproduce the behavior:

  1. I created a .NET Solution that produces the error with the current svc-util v8.0.0
  2. You have to run the build.ps1 file
  3. It crahes on CodeExporter.GetReferencedType

When serializing the object it throws a null reference exception

---> System.NullReferenceException: Object reference not set to an instance of an object.
  at System.Runtime.Serialization.DataMember.CriticalHelper.get_MemberType() in C:\Github\wcf\src\dotnet-svcutil\lib\src\FrameworkFork\System.Runtime.Serialization\System\Runtime\Serialization\DataMember.cs:line 264
  at System.Runtime.Serialization.DataMember.get_MemberType() in C:\Github\wcf\src\dotnet-svcutil\lib\src\FrameworkFork\System.Runtime.Serialization\System\Runtime\Serialization\DataMember.cs:line 142

Fix

The fix is to change to comparison in CodeExporter.GetReferencedType (Line 563)

from: if (referencedContract.Equals(dataContract))
to: if (referencedContract.StableName.Equals(dataContract.StableName))

Expected behavior
That the Reference.cs will be created with respect to the referenced data types.

Screenshots
If applicable, add screenshots to help explain your problem.

Image

Error_WSDL_DataContract.zip

Activity

  1. BitKFu commented on Jul 10, 2025

    @BitKFu
    ContributorAuthor

    I added a pull request, that fixes the issue: #5807

  2. imcarolwang commented on Jul 11, 2025

    @imcarolwang
    Contributor

    My investigation of the issue suggests that the tool tries to reuse types from referenced assemblies. When comparing a referenced DataContract type with one exported from the schema, it appears to detect a difference in the IsReference property, which results in the exception being thrown.

    Based on the reproducing app provided, I haven’t yet determined why there is inconsistency in how IsReference is resolved for the DataContract types, likely because of the complex relationships and hierarchies among the types.

    Switching the comparison to use only referencedContract.StableName does avoid the mismatch in this particular case. However, the original equality check also compares properties like IsReference, which is the actual cause of the types not matching. While skipping that check works here, it could potentially lead to incorrect type reuse in other situations where those differences matter.

  3. imcarolwang commented on Jul 15, 2025

    @imcarolwang
    Contributor

    The repro app and suggested fix mentioned in the issue have been very helpful in investigating the problem. Thanks to this, a new PR has been created, which is hoped to resolve the issue reliably.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions