Skip to content
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

Comparing symbols using only one set of references can result in false differences due inconsistent compare strings #46834

Open
ericstj opened this issue Feb 13, 2025 · 1 comment
Labels
Area-NetSDK untriaged Request triage from a team member

Comments

@ericstj
Copy link
Member

ericstj commented Feb 13, 2025

Describe the bug

When APICompat is comparing libraries from different frameworks and only has one set of references, and those references differ on CoreLib, APICompat may generate identifiers that are not consistent

To Reproduce

Discovered in dotnet/wcf#5742 (comment)

While debugging I noticed the comparsion strings for the two sides differ:

System.Nullable<System.Int32> System.ServiceModel.Federation.WSTrustTokenParameters.KeySize.get
System.Int32? System.ServiceModel.Federation.WSTrustTokenParameters.KeySize.get

Roslyn has enough to resolve that System.Nullable<System.Int32> should be System.Int32? but it is not.

It seems like this is due to the fact that in this case, the left symbol references Nullable in System.Runtime 8.0 - but right hand side has System.Runtime in netstandard. The right hand side references do contain a facade for System.Runtime that can forward the type to netstandard, but roslyn doesn't appear to be resolving this. It could be due to the version mismatch (netstandard's System.Runtime is version 4.1.2.0).

It's pretty unusual to do this type of comparison where a package replaces a framework specific asset (net8.0) with a more generic asset (netstandard2.0) and in general this comparison is not compatible from a consumption side of things (consuming net8.0 in netstandard2.0) but it is compatible from a production perspective.

@ericstj
Copy link
Member Author

ericstj commented Feb 13, 2025

Looks like this is due to us not providing references for the left-hand-side.

if (leftContentItems[0].Properties.TryGetValue("tfm", out object? tfmObj) && tfmObj is NuGetFramework leftTargetFramework)
{
fallbackAssemblyReferences = rightPackage.FindBestAssemblyReferencesForFramework(leftTargetFramework);
}

If I force the compiler to use the same references that we use for the right-hand-side (even though the framework is not compatible) It is enough to avoid this error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-NetSDK untriaged Request triage from a team member
Projects
None yet
Development

No branches or pull requests

1 participant