stryker-mutator / stryker-net

Mutation testing for .NET core and .NET framework!
https://stryker-mutator.io
Apache License 2.0
1.75k stars 176 forks source link

Unhandled exception. System.MissingMethodException #2776

Open CzBuCHi opened 7 months ago

CzBuCHi commented 7 months ago

Describe the bug when running striker via bash using dotnet stryker -O "../../StrykerOutput/$test_name" -p "$test_name.csproj" -r html -r json -r progress command (CWD is test project directory) im getting exception bellow

Logs

[18:20:06 INF] Time Elapsed 00:00:08.7951736
Unhandled exception. System.MissingMethodException: Method not found: 'System.Collections.Generic.IEnumerator`1<Microsoft.CodeAnalysis.NodeStateEntry`1<System.ValueTuple`2<System.__Canon,System.__Canon>>> Microsoft.CodeAnalysis.NodeStateTable`1.GetEnumerator()'.
   at Microsoft.CodeAnalysis.ExternalAccess.RazorCompiler.HostOutputNode`1.AppendOutputs(IncrementalExecutionContext context, CancellationToken cancellationToken)
   at Microsoft.CodeAnalysis.GeneratorDriver.UpdateOutputs(ImmutableArray`1 outputNodes, IncrementalGeneratorOutputKind outputKind, Builder generatorRunStateBuilder, CancellationToken cancellationToken, Builder driverStateBuilder)
   at Microsoft.CodeAnalysis.GeneratorDriver.RunGeneratorsCore(Compilation compilation, DiagnosticBag diagnosticsBag, CancellationToken cancellationToken)
   at Microsoft.CodeAnalysis.GeneratorDriver.RunGeneratorsAndUpdateCompilation(Compilation compilation, Compilation& outputCompilation, ImmutableArray`1& diagnostics, CancellationToken cancellationToken)
   at Stryker.Core.Compiling.CsharpCompilingProcess.RunSourceGenerators(IAnalyzerResult analyzerResult, Compilation compilation) in /_/src/Stryker.Core/Stryker.Core/Compiling/CsharpCompilingProcess.cs:line 116
   at Stryker.Core.Compiling.CsharpCompilingProcess.GetCSharpCompilation(IEnumerable`1 syntaxTrees) in /_/src/Stryker.Core/Stryker.Core/Compiling/CsharpCompilingProcess.cs:line 144
   at Stryker.Core.Compiling.CsharpCompilingProcess.GetSemanticModels(IEnumerable`1 syntaxTrees) in /_/src/Stryker.Core/Stryker.Core/Compiling/CsharpCompilingProcess.cs:line 102
   at Stryker.Core.MutationTest.CsharpMutationProcess.Mutate(MutationTestInput input) in /_/src/Stryker.Core/Stryker.Core/MutationTest/CsharpMutationProcess.cs:line 59
   at Stryker.Core.MutationTest.MutationTestProcess.Mutate() in /_/src/Stryker.Core/Stryker.Core/MutationTest/MutationTestProcess.cs:line 88
   at Stryker.Core.Initialisation.ProjectMutator.MutateProject(StrykerOptions options, MutationTestInput input, IReporter reporters) in /_/src/Stryker.Core/Stryker.Core/Initialisation/ProjectMutator.cs:line 38
   at Stryker.Core.Initialisation.ProjectOrchestrator.MutateProjects(StrykerOptions options, IReporter reporters, ITestRunner runner)+MoveNext() in /_/src/Stryker.Core/Stryker.Core/Initialisation/ProjectOrchestrator.cs:line 68
   at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
   at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
   at Stryker.Core.StrykerRunner.RunMutationTest(IStrykerInputs inputs, ILoggerFactory loggerFactory, IProjectOrchestrator projectOrchestrator) in /_/src/Stryker.Core/Stryker.Core/StrykerRunner.cs:line 61
   at Stryker.CLI.StrykerCli.RunStryker(IStrykerInputs inputs) in /_/src/Stryker.CLI/Stryker.CLI/StrykerCLI.cs:line 93
   at Stryker.CLI.StrykerCli.<>c__DisplayClass10_0.<Run>b__0() in /_/src/Stryker.CLI/Stryker.CLI/StrykerCLI.cs:line 68
   at McMaster.Extensions.CommandLineUtils.CommandLineApplication.<>c__DisplayClass143_0.<OnExecute>b__0(CancellationToken _)
   at McMaster.Extensions.CommandLineUtils.CommandLineApplication.ExecuteAsync(String[] args, CancellationToken cancellationToken)
   at McMaster.Extensions.CommandLineUtils.CommandLineApplication.Execute(String[] args)
   at Stryker.CLI.StrykerCli.Run(String[] args) in /_/src/Stryker.CLI/Stryker.CLI/StrykerCLI.cs:line 74
   at Stryker.CLI.Program.Main(String[] args) in /_/src/Stryker.CLI/Stryker.CLI/Program.cs:line 14

Expected behavior A clear and concise description of what you expected to happen.

Desktop (please complete the following information):

Additional notes reverting back to 3.11.0 fixed my issue

geeknz commented 7 months ago

I had the same issue running with no options. I'm using 3.11.0 for now.

dupdob commented 7 months ago

This looks like a bug with Roslyn compiler judging by the exception and by the fact that V3.12 was released to include the latest version of said libraries.

rouke-broersma commented 7 months ago

Looks like an issue with running source generators for razor and/or minimal api

LouisMach commented 6 months ago

I'm having the same issue where this error popped up running Stryker 3.13.1 with target .net 7.0.404. Stryker 3.11 works, although some tests are failing in Stryker while they work through the CLI.

AndyCC25 commented 3 months ago

Here I have the same error

[14:17:12 ERR] An error occurred during the mutation test run System.AggregateException: One or more errors occurred. (Method not found: 'System.Collections.Generic.IEnumerator1<Microsoft.CodeAnalysis.NodeStateEntry1<System.ValueTuple2<System.__Canon,System.__Canon>>> Microsoft.CodeAnalysis.NodeStateTable1.GetEnumerator()'.) ---> System.MissingMethodException: Method not found: 'System.Collections.Generic.IEnumerator1<Microsoft.CodeAnalysis.NodeStateEntry1<System.ValueTuple2<System.__Canon,System.__Canon>>> Microsoft.CodeAnalysis.NodeStateTable1.GetEnumerator()'. at Microsoft.CodeAnalysis.ExternalAccess.RazorCompiler.HostOutputNode1.AppendOutputs(IncrementalExecutionContext context, CancellationToken cancellationToken) at Microsoft.CodeAnalysis.GeneratorDriver.UpdateOutputs(ImmutableArray1 outputNodes, IncrementalGeneratorOutputKind outputKind, Builder generatorRunStateBuilder, CancellationToken cancellationToken, Builder driverStateBuilder) at Microsoft.CodeAnalysis.GeneratorDriver.RunGeneratorsCore(Compilation compilation, DiagnosticBag diagnosticsBag, CancellationToken cancellationToken) at Microsoft.CodeAnalysis.GeneratorDriver.RunGeneratorsAndUpdateCompilation(Compilation compilation, Compilation& outputCompilation, ImmutableArray1& diagnostics, CancellationToken cancellationToken) at Stryker.Core.Compiling.CsharpCompilingProcess.RunSourceGenerators(IAnalyzerResult analyzerResult, Compilation compilation) in /_/src/Stryker.Core/Stryker.Core/Compiling/CsharpCompilingProcess.cs:line 121 at Stryker.Core.Compiling.CsharpCompilingProcess.GetCSharpCompilation(IEnumerable1 syntaxTrees) in //src/Stryker.Core/Stryker.Core/Compiling/CsharpCompilingProcess.cs:line 160 at Stryker.Core.Compiling.CsharpCompilingProcess.GetSemanticModels(IEnumerable`1 syntaxTrees) in //src/Stryker.Core/Stryker.Core/Compiling/CsharpCompilingProcess.cs:line 103 at Stryker.Core.MutationTest.CsharpMutationProcess.Mutate(MutationTestInput input) in //src/Stryker.Core/Stryker.Core/MutationTest/CsharpMutationProcess.cs:line 59 at Stryker.Core.MutationTest.MutationTestProcess.Mutate() in //src/Stryker.Core/Stryker.Core/MutationTest/MutationTestProcess.cs:line 88 at Stryker.Core.Initialisation.ProjectMutator.MutateProject(StrykerOptions options, MutationTestInput input, IReporter reporters) in /_/src/Stryker.Core/Stryker.Core/Initialisation/ProjectMutator.cs:line 38 at Stryker.Core.Initialisation.ProjectOrchestrator.<>cDisplayClass7_0.b_0(MutationTestInput mutationTestInput) in //src/Stryker.Core/Stryker.Core/Initialisation/ProjectOrchestrator.cs:line 70 at System.Threading.Tasks.Parallel.<>cDisplayClass19_02.<ForWorker>b__1(RangeWorker& currentWorker, Int64 timeout, Boolean& replicationDelegateYieldedBeforeCompletion) --- End of stack trace from previous location --- at System.Threading.Tasks.Parallel.<>c__DisplayClass19_02.b__1(RangeWorker& currentWorker, Int64 timeout, Boolean& replicationDelegateYieldedBeforeCompletion) at System.Threading.Tasks.TaskReplicator.Replica.Execute() --- End of inner exception stack trace --- at System.Threading.Tasks.TaskReplicator.Run[TState](ReplicatableUserAction1 action, ParallelOptions options, Boolean stopOnFirstFailure) at System.Threading.Tasks.Parallel.ForWorker[TLocal,TInt](TInt fromInclusive, TInt toExclusive, ParallelOptions parallelOptions, Action1 body, Action2 bodyWithState, Func4 bodyWithLocal, Func1 localInit, Action1 localFinally) --- End of stack trace from previous location --- at System.Threading.Tasks.Parallel.ForWorker[TLocal,TInt](TInt fromInclusive, TInt toExclusive, ParallelOptions parallelOptions, Action1 body, Action2 bodyWithState, Func4 bodyWithLocal, Func1 localInit, Action1 localFinally) at System.Threading.Tasks.Parallel.ForEachWorker[TSource,TLocal](IEnumerable1 source, ParallelOptions parallelOptions, Action1 body, Action2 bodyWithState, Action3 bodyWithStateAndIndex, Func4 bodyWithStateAndLocal, Func5 bodyWithEverything, Func1 localInit, Action`1 localFinally)

Running the striker over a .NET 8 blazor with webassembly project

dupdob commented 2 months ago

thanks for the report. Your comment led me to realize that the exception occurs while generating the semantic model for the source code. To this day, this information is hardly used by Stryker, so a quick fix could be to simply ignore the exception and move forward without the semantic model

rouke-broersma commented 2 months ago

@dupdob at the time when this issue was opened we did not generate the semantic model. Are you referring only to the last comment?

dupdob commented 2 months ago

It appears in all stack traces here

rouke-broersma commented 2 months ago

I looked through the history and appears I was incorrect, we did in fact add semantic model before this issue was created. Sorry!

dupdob commented 2 months ago

no worries. Focusing on the issue: I just realized that we generate the semantic model before any actual compilation attempt. So there is a good chance this will happen even if we skip the semantic model generation step. That being said, my PR from a few weeks ago may fix that. @AndyCC25, which Stryker's version are you using ?

AndyCC25 commented 2 months ago

I'm using the version 4.0.3

dupdob commented 2 months ago

thanks, so it contains an improvement regarding generators related settings. Which I hoped would fix all existing issues. Clearly, it does not solve this one.

AndyCC25 commented 2 months ago

@dupdob any news on this one, there is a plan to fix this issue?

dupdob commented 2 months ago

hi @AndyCC25, short answer is no. As in: we do not have a clear plan on how to fix this, but we would like to fix it. until we have a project and/or scenario to reproduce it, the best we can do is shoot in the dark (like the previous fix). Without one, we cannot analyze what causes this: it may be that Stryker generates compilation errors that simply crashes Roslyn (while the C# compiler properly reports the syntax error), it may be that we some compilation symbols or environment variables are missing, it may be a version conflict between Razor SDK and Stryker or some other prerequisite we are not aware of. Is there any chance you can share a small project reproducing the issue?

AndyCC25 commented 2 months ago

@dupdob I tried from a scratch project and didn't reproduce the issue, I'm was using blazor with web assembly mode and now in my new project there is no problems, I would probably go and check what is different in my previous project where the issue was happening