we are working with SyntaxEditor and have implemented our own Language called BDL. Everything works fine except from time to time our UI-test-machine delivers a crash dump with the following exception:
Collection was modified; enumeration operation may not execute. at System.ThrowHelper.ThrowInvalidOperationException(ExceptionResource resource) at System.Collections.Generic.Dictionary`2.KeyCollection.Enumerator.MoveNext() at ActiproSoftware.Text.Implementation.CodeDocument.GetServices[#Mnc](ISyntaxLanguage #6Bf) at ActiproSoftware.Text.Implementation.CodeDocument.OnParseDataChanged(ParseDataPropertyChangedEventArgs e) at ActiproSoftware.Text.Implementation.CodeDocument.set_ParseData(IParseData value) at ActiproSoftware.Text.Implementation.CodeDocument.NotifyParseComplete(IParseRequest request, IParseData result) at ActiproSoftware.Text.Implementation.CodeDocument.#bGc(IParseRequest #FMc, IParseData #GF) at ActiproSoftware.Text.Parsing.Implementation.ThreadedParseRequestDispatcher.#0Yc.#nXc(IParseRequest #FMc) at ActiproSoftware.Text.Parsing.Implementation.ThreadedParseRequestDispatcher.#0Yc.#56c() at System.Threading.ThreadHelper.ThreadStart_Context(Object state) at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) at System.Threading.ThreadHelper.ThreadStart()
But we never register a service with the Document, but only with the language. In the constructor of our BdlLanguage-class a lot of RegisterService-calls are done. Then we build up our ViewModel, that contains an instance of CodeDocument, where the BdlLanguage instance is assigned to the CodeDocument.Language property and where also 2 more Services are registered. Finally the ViewModel is bound to the UI control. There the SyntaxEditor control has an event-handler OnDocumentChanged where a UI-related service (CustomSquiggleTagQuickInfoProvider) is registered on the new Documents language.
Is this bad design? Is it intended to register all the services within the constructor of the language class only? Is there any chance to lock the collection of registered services to avoid this exception? Except for the ui related service all other services are exactly the same for all document instances. Is it possible to have some static shared Services-collection that is registered once at program start to avoid this exception?
[Modified 4 years ago]