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

MSBuild inconsistent file path to the same Task assembly load casing cast error #5080

Closed
wli3 opened this issue Jan 27, 2020 · 4 comments
Closed
Assignees
Labels

Comments

@wli3
Copy link

wli3 commented Jan 27, 2020

Steps to reproduce

Failed to build https://github.com/dotnet-maestro-bot/cli/tree/merge/release/3.1.1xx-to-release/3.1.2xx due to error:

C:\work\cli\src\Microsoft.DotNet.MSBuildSdkResolver\Microsoft.DotNet.MSBuildSdkResolver.csproj]
C:\work\cli\.packages\microsoft.build.tasks.git\1.0.0-beta2-19367-01\buildCrossTargeting\Microsoft.Build.Tasks.Git.targets(24,5): error MSB4018: 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=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e' in the context 'Default' at location 'C:\work\cli\.dotnet\shared\Microsoft.NETCore.App\3.1.2\System.Private.CoreLib.dll'. Type B originates from 'System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e' in the context 'Default' at location 'C:\work\cli\.dotnet\shared\Microsoft.NETCore.App\3.1.2\System.Private.CoreLib.dll'. [C:\work\cli\src\Microsoft.DotNet.MSBuildSdkResolver\Microsoft.DotNet.MSBuildSdkResolver.csproj]
C:\work\cli\.packages\microsoft.build.tasks.git\1.0.0-beta2-19367-01\buildCrossTargeting\Microsoft.Build.Tasks.Git.targets(24,5): error MSB4018:    at Microsoft.Build.Tasks.Git.RepositoryTask.TryGetCachedRepositoryInstance(String cacheKey, Boolean requireCached, GitRepository& repository) in /_/src/Microsoft.Build.Tasks.Git/RepositoryTask.cs:line 135 [C:\work\cli\src\Microsoft.DotNet.MSBuildSdkResolver\Microsoft.DotNet.MSBuildSdkResolver.csproj]

The same assembly with different path is loaded
image

It is caused by path in https://github.com/microsoft/msbuild/blob/86d9494e446de002ea6a4f08d6fbd111b1041059/src/Shared/CoreCLRAssemblyLoader.cs#L32 is not normalized.

@rainersigwald
Copy link
Member

The task in question here uses RegisterTaskObject/GetRegisteredTaskObject to store and retrieve an object across invocations.

https://github.com/dotnet/sourcelink/blob/39c946a79b0daca4e47ec6d23554fea69f33253d/src/Microsoft.Build.Tasks.Git/RepositoryTask.cs#L153-L160

This retrieves an object from an ALC loaded through one path (build/../foo.dll) into an ALC loaded through another (buildCrossTargeting/../foo.dll), which causes the problems.

@dsplaisted
Copy link
Member

@rainersigwald So do you know what we need to do to fix this? Do keys for task objects need to now be aware of the ALC?

@rainersigwald
Copy link
Member

There's an easy fix here for task objects used within a single assembly: normalize the path to that assembly. There's still a conceivable hole if the register/retrieve goes across assemblies (#5084), but I don't know if that actually happens. Since it might I think we should build an escape hatch back to legacy one-ALC behavior (#5086).

rainersigwald added a commit to rainersigwald/msbuild that referenced this issue Jan 28, 2020
Fixes dotnet#5080 by normalizing plugin assembly paths before deduplicating
loads based on those paths.

Does not fix the cross-assembly register/retrieve object problem dotnet#5084.
rainersigwald added a commit to rainersigwald/msbuild that referenced this issue Jan 28, 2020
Fixes dotnet#5080 by normalizing plugin assembly paths before deduplicating
loads based on those paths.

Does not fix the cross-assembly register/retrieve object problem dotnet#5084.
rainersigwald added a commit to rainersigwald/msbuild that referenced this issue Jan 31, 2020
Fixes dotnet#5080 by normalizing plugin assembly paths before deduplicating
loads based on those paths.

Does not fix the cross-assembly register/retrieve object problem dotnet#5084.
@rainersigwald
Copy link
Member

For posterity, this reproed at the commit here: dotnet/cli@cd47882

(thanks @sfoslund!)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants