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.25k stars 754 forks source link

Running Specflow-Tests with dotCover is not possible due to ''BoDi.ObjectContainer' System.Security.VerificationException" #2690

Closed Jazzman82 closed 1 year ago

Jazzman82 commented 1 year ago

SpecFlow Version

3.9.74 (same also on SpecFlow.4.0.16-beta)

Which test runner are you using?

NUnit

Test Runner Version Number

3.13.3

.NET Implementation

equal or greater .NET Framework 4.6.1

Project Format of the SpecFlow project

Classic project format using packages.config

.feature.cs files are generated using

SpecFlow.Tools.MsBuild.Generation NuGet package

Test Execution Method

Command line – PLEASE SPECIFY THE FULL COMMAND LINE

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

No response

Issue Description

When trying to use dotcover CLI https://www.jetbrains.com/help/dotcover/Running_Coverage_Analysis_from_the_Command_LIne.html#basic with a project containing Specflow-Tests, the following exception is thrown:

System.TypeInitializationException : Der Typeninitialisierer für "BoDi.ObjectContainer" hat eine Ausnahme verursacht. ----> System.Security.VerificationException : Dieser Vorgang kann die Laufzeit destabilisieren. bei BoDi.ObjectContainer..ctor(IObjectContainer baseContainer) bei TechTalk.SpecFlow.Infrastructure.ContainerBuilder.CreateGlobalContainer(Assembly testAssembly, IRuntimeConfigurationProvider configurationProvider) in D:\a\1\s\TechTalk.SpecFlow\Infrastructure\ContainerBuilder.cs:Zeile 33. bei TechTalk.SpecFlow.TestRunnerManager.CreateTestRunnerManager(Assembly testAssembly, IContainerBuilder containerBuilder) in D:\a\1\s\TechTalk.SpecFlow\TestRunnerManager.cs:Zeile 247. bei System.Collections.Concurrent.ConcurrentDictionary2.GetOrAdd(TKey key, Func2 valueFactory) bei TechTalk.SpecFlow.TestRunnerManager.GetTestRunnerManager(Assembly testAssembly, IContainerBuilder containerBuilder, Boolean createIfMissing) in D:\a\1\s\TechTalk.SpecFlow\TestRunnerManager.cs:Zeile 207. bei TechTalk.SpecFlow.TestRunnerManager.<OnTestRunStartAsync>d__43.MoveNext() in D:\a\1\s\TechTalk.SpecFlow\TestRunnerManager.cs:Zeile 267. --- Ende der Stapelüberwachung vom vorhergehenden Ort, an dem die Ausnahme ausgelöst wurde --- bei System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() bei System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) bei System.Runtime.CompilerServices.TaskAwaiter.GetResult() bei ClassLibrary1_NUnitAssemblyHooks.<AssemblyInitializeAsync>d__0.MoveNext() in C:\Users\buhlt\RiderProjects\Solution2\ClassLibrary1\obj\Debug\NUnit.AssemblyHooks.cs:Zeile 18. --- Ende der Stapelüberwachung vom vorhergehenden Ort, an dem die Ausnahme ausgelöst wurde --- bei System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() bei System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) bei System.Runtime.CompilerServices.TaskAwaiter1.GetResult() bei NUnit.Framework.Internal.TaskAwaitAdapter.GenericAdapter1.GetResult() bei NUnit.Framework.Internal.AsyncToSyncAdapter.Await(Func1 invoke) bei NUnit.Framework.Internal.Commands.SetUpTearDownItem.RunSetUpOrTearDownMethod(TestExecutionContext context, IMethodInfo method) bei NUnit.Framework.Internal.Commands.SetUpTearDownItem.RunSetUp(TestExecutionContext context) bei NUnit.Framework.Internal.Commands.OneTimeSetUpCommand.<>c__DisplayClass0_0.<.ctor>b__0(TestExecutionContext context) bei NUnit.Framework.Internal.Commands.BeforeTestCommand.Execute(TestExecutionContext context) bei NUnit.Framework.Internal.Commands.BeforeTestCommand.Execute(TestExecutionContext context) bei NUnit.Framework.Internal.Execution.CompositeWorkItem.PerformOneTimeSetUp() --VerificationException bei JetBrains.Profiler.Core.Instrumentation.DataOnStack.JetBrains_Profiler_Core_Instrumentation_Measure(UInt64 , UInt32 ) bei BoDi.ObjectContainer..cctor() in C:\Work\BoDi\BoDi\BoDi.cs:Zeile 594. `

Steps to Reproduce

Link to Repro Project

https://github.com/Jazzman82/SpecFlowDotCoverProblem

Jazzman82 commented 1 year ago

This is obviously a conflict between BoDi-Usage and dotcover. I could reproduce with very simple testproject (no specflow) but only BoDi NuGet-Reference where the problem occurred as well.

This led me to a simple workaround: just exclude BoDi from dotcover (/Filters=-:module=BoDi) and now everything works like a charm!

the whole working commandline is

.\packages\JetBrains.dotCover.CommandLineTools.2022.3.1\tools\dotCover.exe cover /TargetExecutable=packages\NUnit.ConsoleRunner.3.16.2\tools\nunit3-console.exe /TargetWorkingDir=. /Output=coverage.html /TargetArguments=ClassLibrary1\bin\Debug\ClassLibrary1.dll /Filters=-:module=BoDi

Hope this helps someone else also.

github-actions[bot] commented 1 year 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.