You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
ReferencedTypeDoesNotMatch thrown on correct DataContract #5769
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:
I created a .NET Solution that produces the error with the current svc-util v8.0.0
You have to run the build.ps1 file
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.
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.
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.
Activity
BitKFu commentedon Jul 10, 2025
I added a pull request, that fixes the issue: #5807
imcarolwang commentedon Jul 11, 2025
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.
imcarolwang commentedon Jul 15, 2025
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.