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

FIx build errors with live (SCI) runtime dependencies when targeting NetPrevious (net9.0) in source-build (VMR) #76486

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

Conversation

ViktorHofer
Copy link
Member

@ViktorHofer ViktorHofer commented Dec 18, 2024

Unblocks dotnet/sdk#45427

Fixes the following two errors:

  • src/Features/Core/Portable/ExternalAccess/Watch/Api/WatchHotReloadService.cs(217,13): error CS1503: Argument 4: cannot convert from 'System.Collections.Immutable.ImmutableHashSet<Microsoft.CodeAnalysis.Project>' to 'System.Collections.Generic.IReadOnlySet<Microsoft.CodeAnalysis.Project>' [src/Features/Core/Portable/Microsoft.CodeAnalysis.Features.csproj::TargetFramework=net9.0]
  • src/roslyn/src/Features/Core/Portable/ExternalAccess/Watch/Api/WatchHotReloadService.cs(218,13): error CS1503: Argument 5: cannot convert from 'System.Collections.Immutable.ImmutableHashSet<Microsoft.CodeAnalysis.Project>' to 'System.Collections.Generic.IReadOnlySet<Microsoft.CodeAnalysis.Project>' [src/roslyn/src/Features/Core/Portable/Microsoft.CodeAnalysis.Features.csproj::TargetFramework=net9.0]

The underlying SDK being used is "10.0.100-alpha.1.24555.54"

@ViktorHofer ViktorHofer requested a review from a team as a code owner December 18, 2024 13:38
@dotnet-issue-labeler dotnet-issue-labeler bot added Area-IDE untriaged Issues and PRs which have not yet been triaged by a lead labels Dec 18, 2024
@CyrusNajmabadi
Copy link
Member

Why did this break? Why can't an immutable hash set be passed to a read only set?

@ViktorHofer
Copy link
Member Author

ViktorHofer commented Dec 18, 2024

Given that this only happens in the source-build leg in the VMR (which uses the latest compiler and latest dependencies) I double checked whether the SBRP's Microsoft.NETCore.App.Ref/9.0.0 ref/System.Collections.Immutable.dll assembly has a wrong definition for ImmutableHashSet<T>. It correctly imports IReadOnlySet<T>:

image

Not sure what's going on here.

@ViktorHofer
Copy link
Member Author

ViktorHofer commented Dec 18, 2024

Oh I see what's going on. This assembly reference is used:

/__w/1/vmr/src/roslyn/artifacts/sb/package-cache/system.collections.immutable/10.0.0-alpha.1.24617.1/lib/netstandard2.0/System.Collections.Immutable.dll

and so this branch is entered: https://github.com/dotnet/runtime/blob/237c7594967573e809db40b09dded0d4a6d98cec/src/libraries/System.Collections.Immutable/src/System/Collections/Immutable/ImmutableHashSet_1.cs#L20

@ViktorHofer
Copy link
Member Author

ViktorHofer commented Dec 18, 2024

This is happening because of what was discussed in #76354. Roslyn builds the NetPrevious TFM in the product source-build but its dependencies only target NetCurrent and netstandard2.0. As NetPrevious can't use the NetCurrent SCI assembly, it gets the netstandard2.0 assembly in which ImmutableHashSet<T> doesn't inherit from IReadOnlySet<T>.

From what I see, this doesn't fail in the repo source-build leg because the runtime intermediate package isn't used and hence, dependencies don't get upgraded.

cc @jasonmalinowski @jaredpar @jjonescz

@ViktorHofer ViktorHofer marked this pull request as draft December 18, 2024 15:24
@ViktorHofer ViktorHofer force-pushed the FixCompilerErrorForImmutableHashSetWith100Toolset branch 2 times, most recently from 826604a to c8355ff Compare December 18, 2024 15:40
@ViktorHofer ViktorHofer changed the title FIx build errors with newer toolset and dependencies FIx build errors with live SCI runtime dependency when targeting NetPrevious (net9.0) in source-build (VMR) Dec 18, 2024
@ViktorHofer ViktorHofer changed the title FIx build errors with live SCI runtime dependency when targeting NetPrevious (net9.0) in source-build (VMR) FIx build errors with live (SCI) runtime dependencies when targeting NetPrevious (net9.0) in source-build (VMR) Dec 18, 2024
Fixes the following two errors:
- src/Features/Core/Portable/ExternalAccess/Watch/Api/WatchHotReloadService.cs(217,13): error CS1503: Argument 4: cannot convert from 'System.Collections.Immutable.ImmutableHashSet<Microsoft.CodeAnalysis.Project>' to 'System.Collections.Generic.IReadOnlySet<Microsoft.CodeAnalysis.Project>' [src/Features/Core/Portable/Microsoft.CodeAnalysis.Features.csproj::TargetFramework=net9.0]
- src/roslyn/src/Features/Core/Portable/ExternalAccess/Watch/Api/WatchHotReloadService.cs(218,13): error CS1503: Argument 5: cannot convert from 'System.Collections.Immutable.ImmutableHashSet<Microsoft.CodeAnalysis.Project>' to 'System.Collections.Generic.IReadOnlySet<Microsoft.CodeAnalysis.Project>' [src/roslyn/src/Features/Core/Portable/Microsoft.CodeAnalysis.Features.csproj::TargetFramework=net9.0]

The underlying SDK being used is "10.0.100-alpha.1.24555.54"
@ViktorHofer ViktorHofer force-pushed the FixCompilerErrorForImmutableHashSetWith100Toolset branch from c8355ff to 7cb9fb4 Compare December 18, 2024 16:12
@ViktorHofer ViktorHofer marked this pull request as ready for review December 18, 2024 16:14
@ViktorHofer ViktorHofer requested a review from a team as a code owner December 18, 2024 16:14
Copy link
Member

@jaredpar jaredpar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this change is digging the hole deeper. I think we need to go back to the previous fix and do as I suggested originally which is ahve that TFM be both NetCurrent and NetPrevious.

<PackageReference Include="System.Memory" Condition="'$(TargetFramework)' == 'netstandard2.0'" />
<PackageReference Include="System.Reflection.Metadata" />
<PackageReference Include="System.Reflection.Metadata" Condition="'$(TargetFrameworkIdentifier)' != '.NETCoreApp'" />
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes of this nature can't be merged unless we do a full VS validation insertion. This is too core of a change to go through without one.

@ViktorHofer
Copy link
Member Author

ViktorHofer commented Dec 18, 2024

Have that TFM be both NetCurrent and NetPrevious.

I thought that's what we did? Maybe I misunderstood the original change. @jaredpar who would be a good person to drive that change? Btw how would that solve the above described issue?

@jaredpar
Copy link
Member

I thought that's what we did?

No it was changed to be $(NetPrevious) only

https://github.com/dotnet/roslyn/pull/76354/files#diff-00f5693d71dbe7582970cb797b17a1d85497c08a3e2838c8ea7ce2026526b07aR58

Btw how would that solve the above described issue?

Once everything has a $(NetCurrent) target I would assume that fixes the fact it's falling back to a netstandard2.0 target.

@ViktorHofer
Copy link
Member Author

Once everything has a $(NetCurrent) target I would assume that fixes the fact it's falling back to a netstandard2.0 target.

The issue here is that as long as you target NetPrevious in the source-build product, you will get the netstandard2.0 assemblies of runtime packages. Removing NetPrevious from the list should obviously fix the issues but I don't understand how consistently adding NetPrevious to all properties would fix this.

@jaredpar
Copy link
Member

The issue here is that as long as you target NetPrevious in the source-build product, you will get the netstandard2.0 assemblies of runtime packages.

Not sure what to do here then. Roslyn has built NetPrevious and NetCurrent in our SB TFMs for quite some time. It sounds like source build has changed such that this is not valid anymore? If so we can adjust but very unlikely to happen anytime this year. Too big of a change.

@ViktorHofer
Copy link
Member Author

ViktorHofer commented Dec 18, 2024

Not sure what to do here then. Roslyn has built NetPrevious and NetCurrent in our SB TFMs for quite some time. It sounds like source build has changed such that this is not valid anymore?

Nothing changed outside of roslyn. Runtime packages always only had NetCurrent and netstandard2.0 assemblies in their source-built packages. The change that regressed this is e75664f. It wasn't caught in your repo source-build validation because you don't use the "live" runtime packages there. But it blocked the roslyn -> dotnet/sdk insertion as the source-build leg is failing: dotnet/sdk#44874. I meanwhile submitted a VMR patch from this PR to get the insertion unblocked.

@jaredpar
Copy link
Member

@tmat, @jasonmalinowski you all will need to decide how to handle this. At the moment the workspace layer is using NetPrevious in source build. That will end up using netstandard2.0 versions of some libraries that have different API sets. The change e75664f is hitting one of these gaps.

Overall we may want to just delete NetPrevious from full source build. That's not happening until Jan though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-IDE untriaged Issues and PRs which have not yet been triaged by a lead VSCode
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants