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

Messenger is throwing an exception because the collection of subscribers has been modified. #658

Open
smithmx opened this issue Jun 19, 2015 · 2 comments

Comments

@smithmx
Copy link
Contributor

smithmx commented Jun 19, 2015

System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.InvalidOperationException: Collection was modified; enumeration operation may not execute.
at System.Collections.Generic.List1.Enumerator.MoveNextRare() at Bifrost.Messaging.Messenger.Publish[T](T content) at Drofus.Components.UI.Views.SystemComponentsViewModel.Refresh(Object sender) --- End of inner exception stack trace --- at mscorlib!0x06001205!System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor) at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments) at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) at System.Reflection.MethodBase.Invoke(Object obj, Object[] parameters) at Bifrost.Execution.WeakDelegate.DynamicInvoke(Object[] arguments) at Bifrost.Messaging.Messenger.Publish[T](T content) at Nosyko.Drofus.Revit.DrofusRevitPlugin.ProcessTask(UIApplication uiapp, Queue1 tasks)

Instead of

foreach (var subscriber in _subscribers[type])

we should do

foreach (var subscriber in _subscribers[type].ToList())

@einari
Copy link
Contributor

einari commented Jun 19, 2015

Would it be an option to make the _subscribers a ConcurrentBag instead.

@smithmx
Copy link
Contributor Author

smithmx commented Jun 19, 2015

Yeah, that's fine as well. It might even be better as we are more likely removing subscriptions while iterating than adding them.

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

No branches or pull requests

2 participants