Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NullReference exception: BoDi.ObjectContainerException: Object container disposed (MSTest) #2748

Open
7timus opened this issue May 10, 2024 · 2 comments
Labels

Comments

@7timus
Copy link

7timus commented May 10, 2024

SpecFlow Version

3.8.7

Which test runner are you using?

MSTest

Test Runner Version Number

3.8.7

.NET Implementation

.NET Core 3.1

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

Visual Studio Test Explorer

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

No response

Issue Description

When running tests with MSTest from OutputAPI example project the ISpecFlowOutputHelper in BrowserDriver.cs dispose method throws null reference exception on disposal. This happens due to already disposed ObjectContainer that is accessed by MSTestContextProvider

Stack trace:

Message: 
TestCleanup method CalculatorSelenium.Specs.Features.CalculatorFeature.TestTearDown threw exception. BoDi.ObjectContainerException: Object container disposed.

  Stack Trace: 
ObjectContainer.AssertNotDisposed()
ObjectContainer.Resolve(Type typeToResolve, ResolutionList resolutionPath, String name)
ObjectContainer.Resolve(Type typeToResolve, String name)
ObjectContainer.Resolve[T](String name)
ObjectContainer.Resolve[T]()
MSTestTestContextProvider.GetTestContext()
MSTestTraceListener.WriteToolOutput(String message)
SpecFlowOutputHelper.WriteLine(String message)
BrowserDriver.Dispose() line 60
ObjectContainer.Dispose()
InternalContextManager`1.DisposeInstance()
InternalContextManager`1.Cleanup()
ContextManager.CleanupScenarioContext()
TestExecutionEngine.OnScenarioEnd()
TestRunner.OnScenarioEnd()
CalculatorFeature.TestTearDown()

Steps to Reproduce

Clone https://github.com/SpecFlowOSS/SpecFlow-Examples/tree/master/OutputAPI/CalculatorSelenium/CalculatorSelenium.Specs.
Change NUnit to MSTest adapter and run any of the tests.

Link to Repro Project

https://github.com/SpecFlowOSS/SpecFlow-Examples/tree/master/OutputAPI/CalculatorSelenium/CalculatorSelenium.Specs

@7timus 7timus added the Bug label May 10, 2024
@7timus
Copy link
Author

7timus commented May 13, 2024

I also noticed the problem with MSTest while running tests in parallel. I duplicated (20 features) the same Calculator feature from the example project and using runsettings configured ClassLevel parallelization on 8 workers. This gives me some null ref exceptions from random tests at each run.

 AddTwoNumbers
   Source: Calculator - Copy (15).feature line 9
   Duration: 1.6 sec

  Message: 
Test method CalculatorSelenium.Specs.Features.Calculator221111Feature.AddTwoNumbers threw exception: 
BoDi.ObjectContainerException: Object container disposed

  Stack Trace: 
ObjectContainer.AssertNotDisposed()
ObjectContainer.Resolve(Type typeToResolve, ResolutionList resolutionPath, String name)
ObjectContainer.Resolve[T](String name)
MSTestTraceListener.WriteToolOutput(String message)
TestTracer.TraceWarning(String text)
InternalContextManager`1.Init(TContext newInstance, IObjectContainer newObjectContainer)
ContextManager.InitializeScenarioContext(ScenarioInfo scenarioInfo)
TestExecutionEngine.OnScenarioInitialize(ScenarioInfo scenarioInfo)
TestRunner.OnScenarioInitialize(ScenarioInfo scenarioInfo)
Calculator221111Feature.ScenarioInitialize(ScenarioInfo scenarioInfo)
Calculator221111Feature.AddTwoNumbers() line 9

@DeLaphante
Copy link

I would advised all to not use Specflow+ Runner or LivingDoc as its currently not being supported or developed - migrate to MsTest or Nunit and also update to latest .net 8+ and use third party reporting libraries such as extent report.

Specflow is working perfectly fine for me with the above changes in the following daily github actions repo -> https://github.com/DeLaphante/CynkyAutomation/actions

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants