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 LoadProjectFileAsyncCore routine, similarly
to what is already done for GetProjectsInSolution.

Fixes dotnet/runtime#101121.
  • Loading branch information
uweigand committed Jul 15, 2024
1 parent 93e2561 commit 3310426
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 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,15 @@ 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 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<int> LoadProjectFileAsyncCore(string projectFilePath, string languageName, CancellationToken cancellationToken)

Check failure on line 171 in src/Workspaces/Core/MSBuild.BuildHost/BuildHost.cs

View check run for this annotation

Azure Pipelines / roslyn-CI (Correctness Correctness_Analyzers)

src/Workspaces/Core/MSBuild.BuildHost/BuildHost.cs#L171

src/Workspaces/Core/MSBuild.BuildHost/BuildHost.cs(171,29): error VSTHRD200: (NETCORE_ENGINEERING_TELEMETRY=Build) Use "Async" suffix in names of methods that return an awaitable type (https://github.com/Microsoft/vs-threading/blob/main/doc/analyzers/VSTHRD200.md)

Check failure on line 171 in src/Workspaces/Core/MSBuild.BuildHost/BuildHost.cs

View check run for this annotation

Azure Pipelines / roslyn-CI (Correctness Correctness_Analyzers)

src/Workspaces/Core/MSBuild.BuildHost/BuildHost.cs#L171

src/Workspaces/Core/MSBuild.BuildHost/BuildHost.cs(171,29): error VSTHRD200: (NETCORE_ENGINEERING_TELEMETRY=Build) Use "Async" suffix in names of methods that return an awaitable type (https://github.com/Microsoft/vs-threading/blob/main/doc/analyzers/VSTHRD200.md)
{
CreateBuildManager();

ProjectFileLoader projectLoader = languageName switch
Expand Down

0 comments on commit 3310426

Please sign in to comment.