InvalidOperationException: Collection was Modified
Reqnroll Version
2.4.1
Which test runner are you using?
NUnit
Test Runner Version Number
4.3.2
.NET Implementation
.NET Framework 4.6.2 or later
Test Execution Method
Visual Studio Test Explorer
Content of reqnroll.json configuration file
No response
Issue Description
TearDown : System.InvalidOperationException : Collection was modified; enumeration operation may not execute.
// <auto-generated />
#pragma warning disable
using System.CodeDom.Compiler;
using System.Diagnostics;
using global::System.Runtime.CompilerServices;
using System.Threading.Tasks;
[GeneratedCode("Reqnroll", "2.4.1")]
[global::NUnit.Framework.SetUpFixture]
public static class CrmDynamicsIntegration_Tests_NUnitAssemblyHooks
{
[global::NUnit.Framework.OneTimeSetUp]
[MethodImpl(MethodImplOptions.NoInlining)]
public static async Task AssemblyInitializeAsync()
{
var currentAssembly = typeof(CrmDynamicsIntegration_Tests_NUnitAssemblyHooks).Assembly;
await global::Reqnroll.TestRunnerManager.OnTestRunStartAsync(currentAssembly);
}
[global::NUnit.Framework.OneTimeTearDown]
[MethodImpl(MethodImplOptions.NoInlining)]
public static async ValueTask AssemblyCleanupAsync()
{
var currentAssembly = typeof(CrmDynamicsIntegration_Tests_NUnitAssemblyHooks).Assembly;
await global::Reqnroll.TestRunnerManager.OnTestRunEndAsync(currentAssembly);
}
}
Erroring on await global::Reqnroll.TestRunnerManager.OnTestRunEndAsync(currentAssembly);
Steps to Reproduce
Run reqnroll feature scenario and give me this error
Link to Repro Project
No response
Stack Trace:
--TearDown
ThrowHelper.ThrowInvalidOperationException(ExceptionResource resource)
Enumerator.MoveNext()
<OfTypeIterator>d__95`1.MoveNext()
WhereEnumerableIterator`1.MoveNext()
ObjectContainer.Dispose()
InternalContextManager`1.DisposeInstance()
<OnScenarioEndAsync>d__39.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
ExceptionDispatchInfo.Throw()
<4 more frames...>
TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
TaskAwaiter.GetResult()
<TestTearDownAsync>d__6.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
ExceptionDispatchInfo.Throw()
TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
GenericAdapter`1.GetResult()
AsyncToSyncAdapter.Await[TResult](TestExecutionContext context, Func`1 invoke)
SetUpTearDownItem.RunSetUpOrTearDownMethod(TestExecutionContext context, IMethodInfo method)
SetUpTearDownItem.RunTearDown(TestExecutionContext context)
Please post the stracktrace
Stack Trace:
--TearDown
ThrowHelper.ThrowInvalidOperationException(ExceptionResource resource)
Enumerator.MoveNext()
<OfTypeIterator>d__95`1.MoveNext()
WhereEnumerableIterator`1.MoveNext()
ObjectContainer.Dispose()
InternalContextManager`1.DisposeInstance()
<OnScenarioEndAsync>d__39.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
ExceptionDispatchInfo.Throw()
<4 more frames...>
TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
TaskAwaiter.GetResult()
<TestTearDownAsync>d__6.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
ExceptionDispatchInfo.Throw()
TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
GenericAdapter`1.GetResult()
AsyncToSyncAdapter.Await[TResult](TestExecutionContext context, Func`1 invoke)
SetUpTearDownItem.RunSetUpOrTearDownMethod(TestExecutionContext context, IMethodInfo method)
SetUpTearDownItem.RunTearDown(TestExecutionContext context)
Hi, could you please post the stacktrace with namespaces?
ObjectContainer.Dispose()
I looks like the dispose of one of the disposables goes wrong. That could be also a registered type on the BoDi container?
This is the only stack trace it provides.
Message: TearDown : System.InvalidOperationException : Collection was modified; enumeration operation may not execute.
Stack Trace:
--TearDown
ThrowHelper.ThrowInvalidOperationException(ExceptionResource resource)
Enumerator.MoveNext()
<OfTypeIterator>d__951.MoveNext() WhereEnumerableIterator1.MoveNext()
ObjectContainer.Dispose() line 746
InternalContextManager1.DisposeInstance() line 51 InternalContextManager1.Cleanup() line 46
ContextManager.CleanupScenarioContext() line 203
<OnScenarioEndAsync>d__39.MoveNext() line 267
--- End of stack trace from previous location where exception was thrown ---
ExceptionDispatchInfo.Throw()
TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
TaskAwaiter.GetResult()
<OnScenarioEndAsync>d__17.MoveNext() line 63
--- End of stack trace from previous location where exception was thrown ---
ExceptionDispatchInfo.Throw()
TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
TaskAwaiter.GetResult()
<TestTearDownAsync>d__6.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
ExceptionDispatchInfo.Throw()
TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
GenericAdapter1.GetResult() AsyncToSyncAdapter.Await[TResult](TestExecutionContext context, Func1 invoke)
SetUpTearDownItem.RunSetUpOrTearDownMethod(TestExecutionContext context, IMethodInfo method)
SetUpTearDownItem.RunTearDown(TestExecutionContext context)
Was able to pull another stack trace with some more information:
at Reqnroll.BoDi.ObjectContainer.AssertNotDisposed() in Reqnroll-2.4.1\Reqnroll\BoDi\ObjectContainer.cs:line 740
at Reqnroll.BoDi.ObjectContainer.Resolve(Type typeToResolve, ResolutionList resolutionPath, String name) in Reqnroll-2.4.1\Reqnroll\BoDi\ObjectContainer.cs:line 572
at Reqnroll.BoDi.ObjectContainer.Resolve(Type typeToResolve, String name) in Reqnroll-2.4.1\Reqnroll\BoDi\ObjectContainer.cs:line 560
at Reqnroll.BoDi.ObjectContainer.Resolve[T](String name) in Reqnroll-2.4.1\Reqnroll\BoDi\ObjectContainer.cs:line 553
at Reqnroll.BoDi.ObjectContainer.Resolve[T]() in Reqnroll-2.4.1\Reqnroll\BoDi\ObjectContainer.cs:line 546
at Reqnroll.Bindings.BindingInvoker.GetExecutionContextHolder(IContextManager contextManager) in Reqnroll-2.4.1\Reqnroll\Bindings\BindingInvoker.cs:line 98
at Reqnroll.Bindings.BindingInvoker.<InvokeBindingAsync>d__5.MoveNext() in Reqnroll-2.4.1\Reqnroll\Bindings\BindingInvoker.cs:line 89
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
at Reqnroll.Infrastructure.TestExecutionEngine.<InvokeHookAsync>d__50.MoveNext() in Reqnroll-2.4.1\Reqnroll\Infrastructure\TestExecutionEngine.cs:line 390
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.GetResult()
at Reqnroll.Infrastructure.TestExecutionEngine.<FireEventsAsync>d__48.MoveNext() in Reqnroll-2.4.1\Reqnroll\Infrastructure\TestExecutionEngine.cs:line 354
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at Reqnroll.Infrastructure.TestExecutionEngine.<FireEventsAsync>d__48.MoveNext() in Reqnroll-2.4.1\Reqnroll\Infrastructure\TestExecutionEngine.cs:line 370
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.GetResult()
at Reqnroll.Infrastructure.TestExecutionEngine.<OnFeatureEndAsync>d__35.MoveNext() in Reqnroll-2.4.1\Reqnroll\Infrastructure\TestExecutionEngine.cs:line 173
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.GetResult()
at Reqnroll.TestRunner.<OnFeatureEndAsync>d__13.MoveNext() in Reqnroll-2.4.1\Reqnroll\TestRunner.cs:line 43
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.GetResult()
at Reqnroll.TestRunnerManager.<FireRemainingAfterFeatureHooks>d__41.MoveNext() in Reqnroll-2.4.1\Reqnroll\TestRunnerManager.cs:line 251
The ObjectContainer._objectPool could be changed while _isDisposed was true (see #594).
This could lead to the shown exception. But note that this is not the root cause of this exception, it just hides the root cause (accessing a disposed ObjectContainer).
@cmbswim89 what Hooks (if any) does this project use? The stack trace indicates something going on in the After feature phase of execution. Would it be possible to post a reproduction project?
@
@cmbswim89 what Hooks (if any) does this project use? The stack trace indicates something going on in the After feature phase of execution. Would it be possible to post a reproduction project?
Yes I do have some After bindings in the tests but have commented those out to see if that was the cause of the error and still receive the error message with no After bindings.
Do you register a IDisposable object to the scenario container?
Could you use the build nuget packages from #594 and retest it with them? Do you still get the same exception?
Closing this due to inactivity. Please let us know if this still an issue and please provide the requested info - thanks!