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

InvalidOperationException thrown from ContextBag.Merge #515

bording opened this Issue Jan 9, 2019 · 1 comment


None yet
1 participant
Copy link

bording commented Jan 9, 2019

When processing messages from the main queue and satellite queues simultaneously, an InvalidOperationException can be thrown in the main pipeline.

System.InvalidOperationException: Collection was modified; enumeration operation may not execute.
   at System.ThrowHelper.ThrowInvalidOperationException(ExceptionResource resource)
   at System.Collections.Generic.Dictionary`2.Enumerator.MoveNext()
   at NServiceBus.Extensibility.ContextBag.Merge(ContextBag context)
   at NServiceBus.MainPipelineExecutor.<Invoke>d__1.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at NServiceBus.Transport.RabbitMQ.MessagePump.<Process>d__29.MoveNext()

This can occur when a satellite message is processed at the same time as a main queue message because the transport is sharing a ContextBag instance.

Who's affected

  • Any user with an endpoint that is processing messages on the main queue and a satellite can potentially be affected.


  • Log entries are seen saying a message is being retried because of the following exception: System.InvalidOperationException: Collection was modified; enumeration operation may not execute.

Backported to

Originally reported in Particular/ServiceControl#1550


This comment has been minimized.

Copy link

bording commented Jan 10, 2019

Fixed by #513

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment