Skip to content

Commit

Permalink
Avoid BuildHost crash in Mono due to missing types
Browse files Browse the repository at this point in the history
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 dotnet/runtime#101121.
  • Loading branch information
uweigand committed Jul 17, 2024
1 parent 93e2561 commit 3bcf996
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/Workspaces/Core/MSBuild.BuildHost/BuildHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -161,9 +161,18 @@ private void EnsureMSBuildLoaded(string projectFilePath)
/// <summary>
/// Returns the target ID of the <see cref="ProjectFile"/> object created for this.
/// </summary>
public async Task<int> LoadProjectFileAsync(string projectFilePath, string languageName, CancellationToken cancellationToken)
public Task<int> LoadProjectFileAsync(string projectFilePath, string languageName, CancellationToken cancellationToken)
{
EnsureMSBuildLoaded(projectFilePath);
return LoadProjectFileCoreAsync(projectFilePath, languageName, cancellationToken);
}

// When using the Mono runtime, the MSBuild types used in this method must be available
// to the JIT during compilation of the method, so they have to be loaded by the caller;
// therefore this method must not be inlined.
[MethodImpl(MethodImplOptions.NoInlining)]
private async Task<int> LoadProjectFileCoreAsync(string projectFilePath, string languageName, CancellationToken cancellationToken)
{
CreateBuildManager();

ProjectFileLoader projectLoader = languageName switch
Expand Down

0 comments on commit 3bcf996

Please sign in to comment.