From 2ddb948618950c2b2e9a2943dadc54629a6a64fa Mon Sep 17 00:00:00 2001 From: Ulrich Weigand Date: Mon, 15 Jul 2024 20:06:03 +0200 Subject: [PATCH] Avoid BuildHost crash in Mono due to missing types The LoadProjectFileAsync routine calls EnsureMSBuildLoaded to make sure the Microsoft.Build.dll is accessible, but requires types from that assembly within the routine itself. This may not always work with Mono, as the JIT may look up the types during compilation. Fixed by splitting out a LoadProjectFileCoreAsync routine, similarly to what is already done for GetProjectsInSolution. Fixes https://github.com/dotnet/runtime/issues/101121. --- src/Workspaces/Core/MSBuild.BuildHost/BuildHost.cs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/Workspaces/Core/MSBuild.BuildHost/BuildHost.cs b/src/Workspaces/Core/MSBuild.BuildHost/BuildHost.cs index 08e8008ad8046..7a39c7190ef54 100644 --- a/src/Workspaces/Core/MSBuild.BuildHost/BuildHost.cs +++ b/src/Workspaces/Core/MSBuild.BuildHost/BuildHost.cs @@ -161,9 +161,15 @@ private void EnsureMSBuildLoaded(string projectFilePath) /// /// Returns the target ID of the object created for this. /// - public async Task LoadProjectFileAsync(string projectFilePath, string languageName, CancellationToken cancellationToken) + public Task LoadProjectFileAsync(string projectFilePath, string languageName, CancellationToken cancellationToken) { EnsureMSBuildLoaded(projectFilePath); + return LoadProjectFileCoreAsync(projectFilePath, languageName, cancellationToken); + } + + [MethodImpl(MethodImplOptions.NoInlining)] // Do not inline this, since this uses MSBuild types which are being loaded by the caller + private async Task LoadProjectFileCoreAsync(string projectFilePath, string languageName, CancellationToken cancellationToken) + { CreateBuildManager(); ProjectFileLoader projectLoader = languageName switch