SpecFlowOSS / SpecFlow

#1 .NET BDD Framework. SpecFlow automates your testing & works with your existing code. Find Bugs before they happen. Behavior Driven Development helps developers, testers, and business representatives to get a better understanding of their collaboration
https://www.specflow.org/
Other
2.23k stars 752 forks source link

MSB4018: GenerateFeatureFileCodeBehindTask task failed unexpectedly - No process is on the other end of the pipe #2587

Closed echalone closed 2 years ago

echalone commented 2 years ago

SpecFlow Version

3.9.22

Which test runner are you using?

NUnit

Test Runner Version Number

3.13.1

.NET Implementation

.NET 5.0

Project Format of the SpecFlow project

Sdk-style project format

.feature.cs files are generated using

SpecFlow.Tools.MsBuild.Generation NuGet package

Test Execution Method

TFS/VSTS/Azure DevOps – Task DotNetCoreCLI@0 (dotnet build)

SpecFlow Section in app.config or content of specflow.json

{
    "stepAssemblies": [
        {
            "assembly": "<OurSharedIntegrationTestAssembly>"
        }
    ]
}

Issue Description

Sometimes during dotnet build step the following error is being generated (sometimes for just one specflow project, sometimes for two and sometimes for all three specflow projects):

C:\Users\<UserId>\.nuget\packages\specflow.tools.msbuild.generation\3.9.22\build\SpecFlow.Tools.MsBuild.Generation.targets(93,5): error MSB4018: The "GenerateFeatureFileCodeBehindTask" task failed unexpectedly. [<PathToCsProjectFile>]
C:\Users\<UserId>\.nuget\packages\specflow.tools.msbuild.generation\3.9.22\build\SpecFlow.Tools.MsBuild.Generation.targets(93,5): error MSB4018: System.IO.IOException: No process is on the other end of the pipe. [<PathToCsProjectFile>]
C:\Users\<UserId>\.nuget\packages\specflow.tools.msbuild.generation\3.9.22\build\SpecFlow.Tools.MsBuild.Generation.targets(93,5): error MSB4018:    at System.ConsolePal.WindowsConsoleStream.Write(ReadOnlySpan`1 buffer) [<PathToCsProjectFile>]
C:\Users\<UserId>\.nuget\packages\specflow.tools.msbuild.generation\3.9.22\build\SpecFlow.Tools.MsBuild.Generation.targets(93,5): error MSB4018:    at System.IO.StreamWriter.Flush(Boolean flushStream, Boolean flushEncoder) [<PathToCsProjectFile>]
C:\Users\<UserId>\.nuget\packages\specflow.tools.msbuild.generation\3.9.22\build\SpecFlow.Tools.MsBuild.Generation.targets(93,5): error MSB4018:    at System.IO.StreamWriter.WriteLine(String value) [<PathToCsProjectFile>]
C:\Users\<UserId>\.nuget\packages\specflow.tools.msbuild.generation\3.9.22\build\SpecFlow.Tools.MsBuild.Generation.targets(93,5): error MSB4018:    at System.IO.TextWriter.SyncTextWriter.WriteLine(String value) [<PathToCsProjectFile>]
C:\Users\<UserId>\.nuget\packages\specflow.tools.msbuild.generation\3.9.22\build\SpecFlow.Tools.MsBuild.Generation.targets(93,5): error MSB4018:    at System.Console.WriteLine(String value) [<PathToCsProjectFile>]
C:\Users\<UserId>\.nuget\packages\specflow.tools.msbuild.generation\3.9.22\build\SpecFlow.Tools.MsBuild.Generation.targets(93,5): error MSB4018:    at TechTalk.SpecFlow.Tracing.DefaultListener.WriteToolOutput(String message) [<PathToCsProjectFile>]
C:\Users\<UserId>\.nuget\packages\specflow.tools.msbuild.generation\3.9.22\build\SpecFlow.Tools.MsBuild.Generation.targets(93,5): error MSB4018:    at TechTalk.SpecFlow.Configuration.ConfigurationLoader.TraceConfigSource(ITraceListener traceListener, SpecFlowConfiguration specFlowConfiguration) [<PathToCsProjectFile>]
C:\Users\<UserId>\.nuget\packages\specflow.tools.msbuild.generation\3.9.22\build\SpecFlow.Tools.MsBuild.Generation.targets(93,5): error MSB4018:    at TechTalk.SpecFlow.Generator.GeneratorContainerBuilder.CreateContainer(SpecFlowConfigurationHolder configurationHolder, ProjectSettings projectSettings, IEnumerable`1 generatorPluginInfos, IObjectContainer parentObjectContainer) [<PathToCsProjectFile>]
C:\Users\<UserId>\.nuget\packages\specflow.tools.msbuild.generation\3.9.22\build\SpecFlow.Tools.MsBuild.Generation.targets(93,5): error MSB4018:    at SpecFlow.Tools.MsBuild.Generation.WrappedGeneratorContainerBuilder.BuildGeneratorContainer(SpecFlowConfigurationHolder specFlowConfigurationHolder, ProjectSettings projectSettings, IReadOnlyCollection`1 generatorPluginInfos, IObjectContainer rootObjectContainer) [<PathToCsProjectFile>]
C:\Users\<UserId>\.nuget\packages\specflow.tools.msbuild.generation\3.9.22\build\SpecFlow.Tools.MsBuild.Generation.targets(93,5): error MSB4018:    at SpecFlow.Tools.MsBuild.Generation.GenerateFeatureFileCodeBehindTaskExecutor.Execute() [<PathToCsProjectFile>]
C:\Users\<UserId>\.nuget\packages\specflow.tools.msbuild.generation\3.9.22\build\SpecFlow.Tools.MsBuild.Generation.targets(93,5): error MSB4018:    at SpecFlow.Tools.MsBuild.Generation.GenerateFeatureFileCodeBehindTask.Execute() [<PathToCsProjectFile>]
C:\Users\<UserId>\.nuget\packages\specflow.tools.msbuild.generation\3.9.22\build\SpecFlow.Tools.MsBuild.Generation.targets(93,5): error MSB4018:    at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute() [<PathToCsProjectFile>]
C:\Users\<UserId>\.nuget\packages\specflow.tools.msbuild.generation\3.9.22\build\SpecFlow.Tools.MsBuild.Generation.targets(93,5): error MSB4018:    at Microsoft.Build.BackEnd.TaskBuilder.ExecuteInstantiatedTask(ITaskExecutionHost taskExecutionHost, TaskLoggingContext taskLoggingContext, TaskHost taskHost, ItemBucket bucket, TaskExecutionMode howToExecuteTask) [<PathToCsProjectFile>]

Steps to Reproduce

Sadly this cannot be realiably reproduced but has happened on two different AMD machines (One Epyc server and one Threadripper PC) so far during the dotnet building of the specflow projects. The .NET 5 SDK in use is 5.0.406 through Visual Studio 2022 Enterprise Edition Version 17.1.5 (Current channel).

Link to Repro Project

No response

SabotageAndi commented 2 years ago

WTH is happening here?

Console.WriteLine is failing

C:\Users\.nuget\packages\specflow.tools.msbuild.generation\3.9.22\build\SpecFlow.Tools.MsBuild.Generation.targets(93,5): error MSB4018: at System.Console.WriteLine(String value) []

Not sure if we can do here anything. 🤷‍♂️

echalone commented 2 years ago

WTH is happening here is about the same reaction I had 😅 If only I could reproduce it reliably... If you think it ain't a problem of SpecFlow, do you have an idea which part may have the bug in it? Maybe Visual Studio or .NET 5 or something like that?

SabotageAndi commented 2 years ago

It can anything that is connected to the Console. That can be .NET, that can be the shell you are using to execute dotnet test. That can be the OS.

What you could try is to make a small console application that calls on a lot of threads Console.WriteLine and execute this like the tests. Perhaps you can reproduce it this way and reduce the possible candidates.

echalone commented 2 years ago

Oh you see, that's the fun part, it's not happening during dotnet test, it's happening during dotnet build... and we didn't change anything in the code for months. It says something along the lines of "SpecFlowFeatureFiles: " then tries to generate the specflow project files but then sometimes generates the above mentioned error during the GenerateFeatureFileCodeBehindTask task. It's also only happening to the SpecFlow projects, though other project types are in the solution too. So that's why I'm suspicious of SpecFlow here ^^

SabotageAndi commented 2 years ago

Mmmm, interesting. I overlooked that this happens in our MSBuild Task. Perhaps there is a problem with Console.WriteLine inside an MSBuild task.

I created a PR to use the MSBuild logging and removed the one output that is running to Console.WriteLine at Compile Time. https://github.com/SpecFlowOSS/SpecFlow/pull/2590

It should be in master and on NuGet next week.

echalone commented 2 years ago

Thank you very much! :) Meanwhile I was already able to exclude PowerShell Core, NodeJS, MSBuild, Visual Studio 2022, the Azure DevOps Build-Agent and .NET 5/6 as the reason for the error. They are all used one way or another and I was able to change them back to an older version with which it still worked a few months back, or even remove them from the build-step if possible, and the error still occured. I also updated them all to the latest version and the error still occured. By now I was also able to reproduce it on an Intel machine, so it's also not AMD specific.

SabotageAndi commented 2 years ago

@echalone new version is pushed to NuGet.org. Please update and try it out and report back if the issue is gone now.

echalone commented 2 years ago

Thank you :) I've already begun testing and will report back in the coming days :)

echalone commented 2 years ago

Alright, after several days of testing I wasn't able to reproduce the issue any longer with version 3.9.74. Looks like it's fixed, thank you :)

Und schöne Grüße von Wien nach Wien übrigens :D

SabotageAndi commented 2 years ago

Awesome! So I close this issue.

Schöne Grüße ebenfalls!

github-actions[bot] commented 2 years ago

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.