Skip to content

Commit 9f86520

Browse files
jaredparuweigand
andauthored
Avoid BuildHost crash in Mono due to missing types (#74994)
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. Co-authored-by: Ulrich Weigand <[email protected]>
1 parent 979d7b2 commit 9f86520

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

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

+10-1
Original file line numberDiff line numberDiff line change
@@ -161,9 +161,18 @@ private void EnsureMSBuildLoaded(string projectFilePath)
161161
/// <summary>
162162
/// Returns the target ID of the <see cref="ProjectFile"/> object created for this.
163163
/// </summary>
164-
public async Task<int> LoadProjectFileAsync(string projectFilePath, string languageName, CancellationToken cancellationToken)
164+
public Task<int> LoadProjectFileAsync(string projectFilePath, string languageName, CancellationToken cancellationToken)
165165
{
166166
EnsureMSBuildLoaded(projectFilePath);
167+
return LoadProjectFileCoreAsync(projectFilePath, languageName, cancellationToken);
168+
}
169+
170+
// When using the Mono runtime, the MSBuild types used in this method must be available
171+
// to the JIT during compilation of the method, so they have to be loaded by the caller;
172+
// therefore this method must not be inlined.
173+
[MethodImpl(MethodImplOptions.NoInlining)]
174+
private async Task<int> LoadProjectFileCoreAsync(string projectFilePath, string languageName, CancellationToken cancellationToken)
175+
{
167176
CreateBuildManager();
168177

169178
ProjectFileLoader projectLoader = languageName switch

0 commit comments

Comments
 (0)