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

Bootstrap stage 2 build failure in Microsoft.Build.Tasks.Git.LocateRepository task #3399

Closed
mthalman opened this issue Apr 19, 2023 · 17 comments · Fixed by dotnet/installer#16187
Assignees
Labels
area-testing Improvements in CI and testing

Comments

@mthalman
Copy link
Member

/vmr/.dotnet/sdk/8.0.100-preview.4.23219.1/Sdks/Microsoft.Build.Tasks.Git/build/Microsoft.Build.Tasks.Git.targets(26,5): error MSB4018: The "Microsoft.Build.Tasks.Git.LocateRepository" task failed unexpectedly.
System.InvalidCastException: [A]System.Runtime.CompilerServices.StrongBox`1[Microsoft.Build.Tasks.Git.GitRepository] cannot be cast to [B]System.Runtime.CompilerServices.StrongBox`1[Microsoft.Build.Tasks.Git.GitRepository]. Type A originates from 'System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e' in the context 'Default' at location '/vmr/.dotnet/shared/Microsoft.NETCore.App/8.0.0-preview.4.23217.4/System.Private.CoreLib.dll'. Type B originates from 'System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e' in the context 'Default' at location '/vmr/.dotnet/shared/Microsoft.NETCore.App/8.0.0-preview.4.23217.4/System.Private.CoreLib.dll'.
   at Microsoft.Build.Tasks.Git.RepositoryTask.TryGetCachedRepositoryInstance(String cacheKey, Boolean requireCached, GitRepository& repository)
   at Microsoft.Build.Tasks.Git.RepositoryTask.GetOrCreateRepositoryInstance()
   at Microsoft.Build.Tasks.Git.RepositoryTask.ExecuteImpl()
   at Microsoft.Build.Tasks.Git.RepositoryTask.Execute()
   at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute()
   at Microsoft.Build.BackEnd.TaskBuilder.ExecuteInstantiatedTask(ITaskExecutionHost taskExecutionHost, TaskLoggingContext taskLoggingContext, TaskHost taskHost, ItemBucket bucket, TaskExecutionMode howToExecuteTask) [/vmr/src/source-build-reference-packages/artifacts/source-build/self/src/src/targetPacks/ILsrc/microsoft.netcore.app.ref/7.0.0/Microsoft.NETCore.App.Ref.7.0.0.csproj]

This occurs in the dependency project build of SBRP when attempting to build Microsoft.NETCore.App.Ref.7.0.0.

Build link (internal only)

@dotnet-issue-labeler
Copy link

I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label.

@mthalman mthalman changed the title Bootstrap stage 2 build failure in Microsoft.Build.Tasks.Git.LocationRepository task Bootstrap stage 2 build failure in Microsoft.Build.Tasks.Git.LocateRepository task Apr 19, 2023
@mthalman
Copy link
Member Author

@MichaelSimons
Copy link
Member

[Triage] The fix for dotnet/sdk#31863 should have come in this morning so this should be fixed.

@MichaelSimons MichaelSimons added area-testing Improvements in CI and testing and removed untriaged labels Apr 20, 2023
@MichaelSimons
Copy link
Member

This is still not resolved.

@MichaelSimons
Copy link
Member

It's possible the packages from prebuilts are causing this. Removing them in dotnet/installer#16176.

@MichaelSimons
Copy link
Member

It's possible the packages from prebuilts are causing this. Removing them in dotnet/installer#16176.

Unfortunately it didn't resolve the issue.

@mthalman
Copy link
Member Author

@tmat, @ViktorHofer - Could you help in determining the cause of this failure?

For context, this is failing in the bootstrap build workflow where we source-build the https://github.com/dotnet/dotnet repo once and then use the outputted SDK as the toolset to build the source again. It fails in that second build.

I've attached the build's binlog:
sourcebuild-dependency-projects.zip

What's odd about the exception message is that it's complaining that Type A can't be cast to Type B even though it reports that Type A and B are the same type from the same assembly file. I suspect that it's possible the message is actually wrong here given that it's a generic type and the real casting issue is with the GitRepository type. It doesn't indicate anything about that type's assembly in the error.

Here's the relevant code doing the cast: https://github.com/dotnet/dotnet/blob/e2903bde31921e07bebca58f03f6b1395dd74802/src/sourcelink/src/Microsoft.Build.Tasks.Git/RepositoryTask.cs#L150

It's possible that use of an MSBuild registered task object is a factor here.

@mthalman
Copy link
Member Author

I took a shot in the dark and added a call to dotnet build-server shutdown right before this line:

https://github.com/dotnet/dotnet/blob/e2903bde31921e07bebca58f03f6b1395dd74802/src/source-build-reference-packages/eng/Build.props#L181

But that made no difference.

@tmat
Copy link
Member

tmat commented Apr 21, 2023

Seems like a dup: dotnet/sourcelink#1007, dotnet/msbuild#8478
@rainersigwald

@mthalman
Copy link
Member Author

@rainersigwald - Please work with @tmat / sourcelink folks to determine a fix or workaround for this. This is blocking the source-build release of 8.0 Preview 4.

@tmat
Copy link
Member

tmat commented Apr 21, 2023

As a workaround I can add try-catch around the cache lookup. It will be a potential build perf issue, but not correctness issue.

@tmat
Copy link
Member

tmat commented Apr 21, 2023

Here: dotnet/sourcelink#1008

@tmat
Copy link
Member

tmat commented Apr 21, 2023

I'm gonna close this issue as it should be addressed by the above workaround. Still keeping the msbuild issue opened to track the root cause.

@tmat tmat closed this as completed Apr 21, 2023
@mthalman
Copy link
Member Author

I'd rather keep this open until our build is actually passing.

@tmat
Copy link
Member

tmat commented May 23, 2023

@mthalman
The log #3399 (comment) shows there are two copies of Source Link assembly loaded to the build process:

image

Is this expected?

@mthalman
Copy link
Member Author

I would think that's a possibility. It would be a scenario where a project has a compile-time dependency on Microsoft.Build.Tasks.Git and the logic of the SDK has a runtime dependency on Microsoft.Build.Tasks.Git.

@rainersigwald
Copy link
Member

That shouldn't be a conflict; the compile-time dependency shouldn't be loaded by any part of MSBuild in a persistent way, while the SDK reference (UsingTask) would.

The log shows that the assembly is being loaded in the latter way from two different paths:

image

This looks like it might be fallout from the temporary situation where that task is present both in the SDK and via package--and I'd expect the long-term fix to be that the package goes away and only the SDK copy is used in sourcebuild.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-testing Improvements in CI and testing
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

4 participants