dotnet / roslyn

The Roslyn .NET compiler provides C# and Visual Basic languages with rich code analysis APIs.
https://docs.microsoft.com/dotnet/csharp/roslyn-sdk/
MIT License
19.04k stars 4.03k forks source link

`MSBuildWorkspace.OpenSolutionAsync(..)` fails with "[BuildHost PID 3328] The BuildHost process exited with -1. Process output:" #75292

Open BrunoJuchli opened 1 month ago

BrunoJuchli commented 1 month ago

Version Used: 4.11.0

Steps to Reproduce

Unfortunately so far I can only reproduce the issue on GitHub's Windows Workflow Runner (image version). Furthermore it's based on closed source so it's a bit of a difficult situation. Therefore I'm looking for guidance how to further investigate the issue - the error / logs I receive are unfortunately not helpful at all.

Expected Behavior

MSBuildWorkspace.OpenSolutionAsync(..) succeeds opening the solution.

Actual Behavior

Workspace Failure

MSBuildWorkspace.WorkspaceFailed reports

[BuildHost PID 3328] The BuildHost process exited with -1. Process output:

(there is no further output).

Exception

OpenSolutionAsync throws an exception reporting

The server disconnected unexpectedly.

(Full output see at the end).

Roslyn Command Line Log File

I've set RoslynCommandLineLogFile but unfortunatley for the reported PID (here 3328) no log file is available (there are for other PIDs).

Further Information

Note, that at the time the error occurs several projects have already been evaluted/built. So it's not that "nothing" works, but rather that at some point it trips.

The solution loading is part of a dotnet tool that I've created. It used to work but now stopped working. I've then tried out updating the Microsoft.Build* packages. Previously I've got the same error as reported here, hence why I tried setting PrivateAssets="analyzers;build"/ on Microsoft.CodeAnalysis.Workspaces.MSBuild.

Tool Project File

The current version looks like:

<Project Sdk="Microsoft.NET.Sdk">

    <PropertyGroup>
        <OutputType>Exe</OutputType>
        <TargetFramework>net8.0</TargetFramework>
        <IsPackable>true</IsPackable>
        <PackAsTool>true</PackAsTool>
        <ToolCommandName>localization</ToolCommandName>
    </PropertyGroup>

    <ItemGroup>
      <ProjectReference Include="..\SmartMe.Localization.Serialization.Json\SmartMe.Localization.Serialization.Json.csproj" />
    </ItemGroup>

    <ItemGroup>
      <PackageReference Include="Microsoft.Bcl.AsyncInterfaces" Version="8.0.0" />
      <PackageReference Include="Microsoft.Build" 
                        Version="17.11.4"
                        ExcludeAssets="runtime"/>
      <PackageReference Include="Microsoft.Build.Locator"
                        Version="1.7.8"/>
      <PackageReference Include="Microsoft.Build.Tasks.Core" 
                        Version="17.11.4"
                        ExcludeAssets="runtime"/>
      <PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces"
                        Version="4.11.0" />
      <PackageReference Include="Microsoft.CodeAnalysis.Workspaces.MSBuild" 
                        Version="4.11.0"
                        PrivateAssets="analyzers;build"/>
      <PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="8.0.1" />
      <PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="8.0.1" />
      <PackageReference Include="Microsoft.Extensions.Options" Version="8.0.2" />
      <PackageReference Include="OneOf" Version="3.0.271" />
      <PackageReference Include="System.CommandLine" Version="2.0.0-beta4.22272.1" NoWarn="NU5104" />
      <PackageReference Include="System.Formats.Asn1" Version="8.0.1" />
      <PackageReference Include="System.Linq.Async" Version="6.0.1" />
      <PackageReference Include="System.Security.Cryptography.Xml" Version="8.0.1" />
      <PackageReference Include="System.Text.Json" Version="8.0.4" />
      <PackageReference Include="System.Threading.Tasks.Dataflow" Version="8.0.1" />
    </ItemGroup>

</Project>

Full output

Loading solution D:\a\smartme-cloud\smartme-cloud\src\smartMeCloud.sln creating workspace opening solution 00:00:01.8159214 Evaluate D:\a\smartme-cloud\smartme-cloud\src\Services\BuisnessServiceHelper\BuisnessServiceHelper.csproj () 00:00:00.8249705 Build D:\a\smartme-cloud\smartme-cloud\src\Services\BuisnessServiceHelper\BuisnessServiceHelper.csproj () 00:00:00.0821148 Evaluate D:\a\smartme-cloud\smartme-cloud\src\Datastore\Datastore.Interfaces\Datastore.Interfaces.csproj () 00:00:00.1566624 Build D:\a\smartme-cloud\smartme-cloud\src\Datastore\Datastore.Interfaces\Datastore.Interfaces.csproj () 00:00:00.0501536 Evaluate D:\a\smartme-cloud\smartme-cloud\src\BCL\BCL\BCL.csproj () 00:00:00.0821780 Build D:\a\smartme-cloud\smartme-cloud\src\BCL\BCL\BCL.csproj () 00:00:00.0120430 Resolve D:\a\smartme-cloud\smartme-cloud\src\BCL\BCL\BCL.csproj (netstandard2.0) ms build warning: Found project reference without a matching metadata reference: D:\a\smartme-cloud\smartme-cloud\src\BCL\BCL\BCL.csproj 00:00:00.0554026 Evaluate D:\a\smartme-cloud\smartme-cloud\src\Common\GeneralHelpers\GeneralHelpers.csproj () 00:00:00.0676442 Build D:\a\smartme-cloud\smartme-cloud\src\Common\GeneralHelpers\GeneralHelpers.csproj () 00:00:00.0058225 Resolve D:\a\smartme-cloud\smartme-cloud\src\Common\GeneralHelpers\GeneralHelpers.csproj (netstandard2.0) ms build warning: Found project reference without a matching metadata reference: D:\a\smartme-cloud\smartme-cloud\src\Common\GeneralHelpers\GeneralHelpers.csproj 00:00:00.0705855 Evaluate D:\a\smartme-cloud\smartme-cloud\src\Domain\Domain.csproj () 00:00:00.1067489 Build D:\a\smartme-cloud\smartme-cloud\src\Domain\Domain.csproj () 00:00:00.0058238 Resolve D:\a\smartme-cloud\smartme-cloud\src\Domain\Domain.csproj (netstandard2.0) ms build warning: Found project reference without a matching metadata reference: D:\a\smartme-cloud\smartme-cloud\src\Domain\Domain.csproj 00:00:00.0684766 Evaluate D:\a\smartme-cloud\smartme-cloud\src\Helpers\Helpers.Cryptography\Helpers.Cryptography.csproj () 00:00:00.0523281 Build D:\a\smartme-cloud\smartme-cloud\src\Helpers\Helpers.Cryptography\Helpers.Cryptography.csproj () 00:00:00.0039411 Resolve D:\a\smartme-cloud\smartme-cloud\src\Helpers\Helpers.Cryptography\Helpers.Cryptography.csproj (netstandard2.0) ms build warning: Found project reference without a matching metadata reference: D:\a\smartme-cloud\smartme-cloud\src\Helpers\Helpers.Cryptography\Helpers.Cryptography.csproj 00:00:00.0532812 Evaluate D:\a\smartme-cloud\smartme-cloud\src\Services\Protocolbuffer\SmartMeProtocolbuffer\SmartMeProtocolbuffer.csproj () 00:00:00.1169666 Build D:\a\smartme-cloud\smartme-cloud\src\Services\Protocolbuffer\SmartMeProtocolbuffer\SmartMeProtocolbuffer.csproj () 00:00:00.0054259 Resolve D:\a\smartme-cloud\smartme-cloud\src\Services\Protocolbuffer\SmartMeProtocolbuffer\SmartMeProtocolbuffer.csproj (netstandard2.0) ms build warning: Found project reference without a matching metadata reference: D:\a\smartme-cloud\smartme-cloud\src\Services\Protocolbuffer\SmartMeProtocolbuffer\SmartMeProtocolbuffer.csproj 00:00:00.7837571 Resolve D:\a\smartme-cloud\smartme-cloud\src\Datastore\Datastore.Interfaces\Datastore.Interfaces.csproj (netstandard2.0) ms build warning: Found project reference without a matching metadata reference: D:\a\smartme-cloud\smartme-cloud\src\Datastore\Datastore.Interfaces\Datastore.Interfaces.csproj 00:00:01.1759999 Resolve D:\a\smartme-cloud\smartme-cloud\src\Services\BuisnessServiceHelper\BuisnessServiceHelper.csproj (netstandard2.0) 00:00:00.0576303 Evaluate D:\a\smartme-cloud\smartme-cloud\src\Services\BuisnessServices\BuisnessServices.csproj () 00:00:00.0815450 Build D:\a\smartme-cloud\smartme-cloud\src\Datastore\Datastore.Redis.PubSub\Datastore.Redis.PubSub.csproj () 00:00:00.0043062 Resolve D:\a\smartme-cloud\smartme-cloud\src\Datastore\Datastore.Redis.PubSub\Datastore.Redis.PubSub.csproj (netstandard2.0) ms build warning: Found project reference without a matching metadata reference: D:\a\smartme-cloud\smartme-cloud\src\Datastore\Datastore.Redis.PubSub\Datastore.Redis.PubSub.csproj 00:00:01.0448623 Resolve D:\a\smartme-cloud\smartme-cloud\src\Services\RepositoriesService\RepositoriesService.csproj (netstandard2.0) ms build warning: Found project reference without a matching metadata reference: D:\a\smartme-cloud\smartme-cloud\src\Services\RepositoriesService\RepositoriesService.csproj 00:00:01.2845721 Resolve D:\a\smartme-cloud\smartme-cloud\src\Datastore\TimeSeriesDataStore\TimeSeriesDataStore.csproj (netstandard2.0) ms build warning: Found project reference without a matching metadata reference: D:\a\smartme-cloud\smartme-cloud\src\Datastore\TimeSeriesDataStore\TimeSeriesDataStore.csproj 00:00:00.0612952 Evaluate D:\a\smartme-cloud\smartme-cloud\src\Services\DataStoreService\DataStoreService.csproj () 00:00:00.1677196 Build D:\a\smartme-cloud\smartme-cloud\src\Services\DataStoreService\DataStoreService.csproj () 00:00:00.0432955 Evaluate D:\a\smartme-cloud\smartme-cloud\src\Services\LegacyEmailSender\LegacyEmailSender.csproj () 00:00:00.1530448 Build D:\a\smartme-cloud\smartme-cloud\src\Services\LegacyEmailSender\LegacyEmailSender.csproj () 00:00:00.0080479 Resolve D:\a\smartme-cloud\smartme-cloud\src\Services\LegacyEmailSender\LegacyEmailSender.csproj (netstandard2.0) ms build warning: Found project reference without a matching metadata reference: D:\a\smartme-cloud\smartme-cloud\src\Services\LegacyEmailSender\LegacyEmailSender.csproj 00:00:00.0425366 Evaluate D:\a\smartme-cloud\smartme-cloud\src\Services\TimeSeries\TimeSeriesService\TimeSeriesService.csproj () 00:00:00.1391901 Build D:\a\smartme-cloud\smartme-cloud\src\Services\TimeSeries\TimeSeriesService\TimeSeriesService.csproj () 00:00:00.0418513 Evaluate D:\a\smartme-cloud\smartme-cloud\src\Services\ObisService\ObisService.csproj () 00:00:00.1103620 Build D:\a\smartme-cloud\smartme-cloud\src\Services\ObisService\ObisService.csproj () 00:00:00.0056235 Resolve D:\a\smartme-cloud\smartme-cloud\src\Services\ObisService\ObisService.csproj (netstandard2.0) ms build warning: Found project reference without a matching metadata reference: D:\a\smartme-cloud\smartme-cloud\src\Services\ObisService\ObisService.csproj 00:00:00.1642345 Resolve D:\a\smartme-cloud\smartme-cloud\src\Services\TimeSeries\TimeSeriesService\TimeSeriesService.csproj (netstandard2.0) ms build warning: Found project reference without a matching metadata reference: D:\a\smartme-cloud\smartme-cloud\src\Services\TimeSeries\TimeSeriesService\TimeSeriesService.csproj 00:00:00.5607533 Resolve D:\a\smartme-cloud\smartme-cloud\src\Services\DataStoreService\DataStoreService.csproj (netstandard2.0) ms build warning: Found project reference without a matching metadata reference: D:\a\smartme-cloud\smartme-cloud\src\Services\DataStoreService\DataStoreService.csproj 00:00:00.0525864 Evaluate D:\a\smartme-cloud\smartme-cloud\src\Services\General\Obis\Obis.csproj () ms build error: [BuildHost PID 3328] The BuildHost process exited with -1. Process output:

00:00:00.0742822 Build D:\a\smartme-cloud\smartme-cloud\src\Services\General\Obis\Obis.csproj () 00:00:00.0042817 Resolve D:\a\smartme-cloud\smartme-cloud\src\Services\General\Obis\Obis.csproj (netstandard2.0) ms build warning: Found project reference without a matching metadata reference: D:\a\smartme-cloud\smartme-cloud\src\Services\General\Obis\Obis.csproj 00:00:00.0557067 Evaluate D:\a\smartme-cloud\smartme-cloud\src\Services\InvoiceService\InvoiceService.csproj () 00:00:00.0694469 Build D:\a\smartme-cloud\smartme-cloud\src\Services\InvoiceService\InvoiceService.csproj () 00:00:00.0034380 Resolve D:\a\smartme-cloud\smartme-cloud\src\Services\InvoiceService\InvoiceService.csproj (netstandard2.0) ms build warning: Found project reference without a matching metadata reference: D:\a\smartme-cloud\smartme-cloud\src\Services\InvoiceService\InvoiceService.csproj 00:00:00.0554620 Evaluate D:\a\smartme-cloud\smartme-cloud\src\Services\PaymentAndAccounts\PaymentAndAccountService\PaymentAndAccountService.csproj () 00:00:00.1506720 Build D:\a\smartme-cloud\smartme-cloud\src\Services\PaymentAndAccounts\PaymentAndAccountService\PaymentAndAccountService.csproj () 00:00:00.0057019 Resolve D:\a\smartme-cloud\smartme-cloud\src\Services\PaymentAndAccounts\PaymentAndAccountService\PaymentAndAccountService.csproj (netstandard2.0) ms build warning: Found project reference without a matching metadata reference: D:\a\smartme-cloud\smartme-cloud\src\Services\PaymentAndAccounts\PaymentAndAccountService\PaymentAndAccountService.csproj 00:00:00.0410159 Evaluate D:\a\smartme-cloud\smartme-cloud\src\Services\SmartMeDeviceService\SmartMeDeviceService.csproj () 00:00:00.1674047 Build D:\a\smartme-cloud\smartme-cloud\src\Services\SmartMeDeviceService\SmartMeDeviceService.csproj () 00:00:00.0086605 Resolve D:\a\smartme-cloud\smartme-cloud\src\Services\SmartMeDeviceService\SmartMeDeviceService.csproj (netstandard2.0) ms build warning: Found project reference without a matching metadata reference: D:\a\smartme-cloud\smartme-cloud\src\Services\SmartMeDeviceService\SmartMeDeviceService.csproj 00:00:05.0852182 Resolve D:\a\smartme-cloud\smartme-cloud\src\Services\BuisnessServices\BuisnessServices.csproj (netstandard2.0) 00:00:00.0462819 Evaluate D:\a\smartme-cloud\smartme-cloud\src\Services\M-BUS\MBusServices\MBusServices.csproj () 00:00:00.2698589 Build D:\a\smartme-cloud\smartme-cloud\src\Services\M-BUS\MBusServices\MBusServices.csproj () 00:00:00.0051773 Resolve D:\a\smartme-cloud\smartme-cloud\src\Services\M-BUS\MBusServices\MBusServices.csproj (netstandard2.0) Unhandled exception: System.Exception: The server disconnected unexpectedly. at Microsoft.CodeAnalysis.MSBuild.RpcClient.InvokeCoreAsync(Int32 targetObject, String methodName, List1 parameters, Type expectedReturnType, CancellationToken cancellationToken) at Microsoft.CodeAnalysis.MSBuild.RpcClient.InvokeAsync[T](Int32 targetObject, String methodName, List1 parameters, CancellationToken cancellationToken) at Microsoft.CodeAnalysis.MSBuild.BuildHostProcessManager.GetBuildHostWithFallbackAsync(BuildHostProcessKind buildHostKind, String projectOrSolutionFilePath, CancellationToken cancellationToken) at Microsoft.CodeAnalysis.MSBuild.MSBuildProjectLoader.Worker.LoadProjectFileInfosAsync(String projectPath, DiagnosticReportingOptions reportingOptions, CancellationToken cancellationToken) at Microsoft.CodeAnalysis.MSBuild.MSBuildProjectLoader.Worker.LoadProjectInfosFromPathAsync(String projectPath, DiagnosticReportingOptions reportingOptions, CancellationToken cancellationToken) at Microsoft.CodeAnalysis.MSBuild.MSBuildProjectLoader.Worker.LoadAsync(CancellationToken cancellationToken) at Microsoft.CodeAnalysis.MSBuild.MSBuildProjectLoader.LoadSolutionInfoAsync(String solutionFilePath, IProgress1 progress, ILogger msbuildLogger, CancellationToken cancellationToken) at Microsoft.CodeAnalysis.MSBuild.MSBuildProjectLoader.LoadSolutionInfoAsync(String solutionFilePath, IProgress1 progress, ILogger msbuildLogger, CancellationToken cancellationToken) at Microsoft.CodeAnalysis.MSBuild.MSBuildWorkspace.OpenSolutionAsync(String solutionFilePath, ILogger msbuildLogger, IProgress`1 progress, CancellationToken cancellationToken) at SmartMe.Localization.JsonExtractor.Solution.Load(SolutionFile solutionFile) in /home/runner/work/SmartMe.Localization.Net/SmartMe.Localization.Net/src/SmartMe.Localization.JsonExtractor/Solution.cs:line 42 at SmartMe.Localization.JsonExtractor.Extractor.Run(SolutionFile solutionFile, IProjectContentWriter projectContentWriter, IDependenciesExporter dependenciesExporter) in /home/runner/work/SmartMe.Localization.Net/SmartMe.Localization.Net/src/SmartMe.Localization.JsonExtractor/Extractor.cs:line 37 at SmartMe.Localization.JsonExtractor.Program.Extract(SolutionFile solutionFile, DirectoryInfo outputFolder) in /home/runner/work/SmartMe.Localization.Net/SmartMe.Localization.Net/src/SmartMe.Localization.JsonExtractor/Program.cs:line 190 at System.CommandLine.Invocation.AnonymousCommandHandler.InvokeAsync(InvocationContext context) at System.CommandLine.Invocation.InvocationPipeline.<>cDisplayClass4_0.<b0>d.MoveNext() --- End of stack trace from previous location --- at System.CommandLine.Builder.CommandLineBuilderExtensions.<>cDisplayClass17_0.<b0>d.MoveNext() --- End of stack trace from previous location --- at System.CommandLine.Builder.CommandLineBuilderExtensions.<>cDisplayClass12_0.<b0>d.MoveNext() --- End of stack trace from previous location --- at System.CommandLine.Builder.CommandLineBuilderExtensions.<>cDisplayClass22_0.<b0>d.MoveNext() --- End of stack trace from previous location --- at System.CommandLine.Builder.CommandLineBuilderExtensions.<>cDisplayClass19_0.<b0>d.MoveNext() --- End of stack trace from previous location --- at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c.<b18_0>d.MoveNext() --- End of stack trace from previous location --- at System.CommandLine.Builder.CommandLineBuilderExtensions.<>cDisplayClass16_0.<b0>d.MoveNext() --- End of stack trace from previous location --- at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c.<b5_0>d.MoveNext() --- End of stack trace from previous location --- at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass8_0.<b__0>d.MoveNext() Error: Process completed with exit code 1.

BrunoJuchli commented 1 day ago

I have updated dependencies to:

Microsoft.Build.Locator is still at 1.7.8 (no update available).

The issue still exists and I can't seem to get any more information. The reported exception message has slightly changed. There's a single roslyn log file like server.6568.log - but it's completely empty (0 bytes).

[BuildHost PID 780] The BuildHost process exited with -1. Process output:

Unhandled exception: System.IO.IOException: The pipe is being closed. at System.IO.RandomAccess.<>c.b__21_0(ValueTuple4 state) at System.Threading.AsyncOverSyncWithIoCancellation.InvokeAsync[TState](Action1 action, TState state, CancellationToken cancellationToken) at System.Runtime.CompilerServices.PoolingAsyncValueTaskMethodBuilder1.StateMachineBox1.System.Threading.Tasks.Sources.IValueTaskSource.GetResult(Int16 token) at System.IO.Strategies.BufferedFileStreamStrategy.WriteToNonSeekableAsync(ReadOnlyMemory1 source, CancellationToken cancellationToken) at System.IO.StreamWriter.<FlushAsyncInternal>g__Core|76_0(Boolean flushStream, Boolean flushEncoder, CancellationToken cancellationToken) at Microsoft.CodeAnalysis.MSBuild.RpcClient.InvokeCoreAsync(Int32 targetObject, String methodName, List1 parameters, Type expectedReturnType, CancellationToken cancellationToken) at Microsoft.CodeAnalysis.MSBuild.RpcClient.InvokeAsync[T](Int32 targetObject, String methodName, List1 parameters, CancellationToken cancellationToken) at Microsoft.CodeAnalysis.MSBuild.BuildHostProcessManager.GetBuildHostWithFallbackAsync(BuildHostProcessKind buildHostKind, String projectOrSolutionFilePath, CancellationToken cancellationToken) at Microsoft.CodeAnalysis.MSBuild.MSBuildProjectLoader.Worker.LoadProjectFileInfosAsync(String projectPath, DiagnosticReportingOptions reportingOptions, CancellationToken cancellationToken) at Microsoft.CodeAnalysis.MSBuild.MSBuildProjectLoader.Worker.LoadProjectInfosFromPathAsync(String projectPath, DiagnosticReportingOptions reportingOptions, CancellationToken cancellationToken) at Microsoft.CodeAnalysis.MSBuild.MSBuildProjectLoader.Worker.LoadAsync(CancellationToken cancellationToken) at Microsoft.CodeAnalysis.MSBuild.MSBuildProjectLoader.LoadSolutionInfoAsync(String solutionFilePath, IProgress1 progress, ILogger msbuildLogger, CancellationToken cancellationToken) at Microsoft.CodeAnalysis.MSBuild.MSBuildProjectLoader.LoadSolutionInfoAsync(String solutionFilePath, IProgress1 progress, ILogger msbuildLogger, CancellationToken cancellationToken) at Microsoft.CodeAnalysis.MSBuild.MSBuildWorkspace.OpenSolutionAsync(String solutionFilePath, ILogger msbuildLogger, IProgress1 progress, CancellationToken cancellationToken) at SmartMe.Localization.JsonExtractor.Solution.Load(SolutionFile solutionFile) in /home/runner/work/SmartMe.Localization.Net/SmartMe.Localization.Net/src/SmartMe.Localization.JsonExtractor/Solution.cs:line 42