From 331042615e08775083000f76e64157f373a7f13f 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 LoadProjectFileAsyncCore 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..aa0dc11a25982 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 LoadProjectFileAsyncCore(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 LoadProjectFileAsyncCore(string projectFilePath, string languageName, CancellationToken cancellationToken) + { CreateBuildManager(); ProjectFileLoader projectLoader = languageName switch