Hello,
I'm getting a Dictionnary exception when using the Import function of the RtfFormatProvider in a Task.
Here's an example of the code that is run:
Private Async Sub LoadItems Dim loadingTasks As New List(Of Task) '-- Async task #1 loadingTasks.Add(Task.Run(Function() LoadData1(paramObj))) '-- Async task #2 loadingTasks.Add(Task.Run(Function() LoadData2(paramObj)))End SubPrivate Function LoadData1(paramObj As Object) Dim objectList = New List(Of MyItemClass) objectList.AddRange(New ObservableCollection(Of MyItemClass)(MyItemClass.GetAll()) Return objectList End Function'In MyItemClass:Public Function GetAll() As List(Of MyItemClass) '[Some code...] Dim frmtValue As String '[Some more code...] Dim doc As New RadDocument() Dim rfp As New RtfFormatProvider() doc = rfp.Import(frmtValue) 'The exception is triggered here '[Some code...]End Function
I'm loading items in parralel using Tasks.
Those items have a property bound to a RichTextBox and I'm deserializing the RTF string in a RadDocument through a RtfFormatProvider.
The code worked fine when I didn't use the Tasks and called the function in a synchronous way. However, since I switch to Tasks, I get the follwing error on the Import method:
"An item with the same key has already been added"
at System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add)
at System.Collections.Generic.Dictionary`2.Add(TKey key, TValue value)
at Telerik.Windows.Documents.FormatProviders.ReplaceStyleNameHandler.Add(String displayName, String name)
at Telerik.Windows.Documents.FormatProviders.ReplaceStyleNameHandler.InitializeStyleDisplayNameToStyleNameDictionary()
at Telerik.Windows.Documents.FormatProviders.ReplaceStyleNameHandler.get_StyleDisplayNameToStyleName()
at Telerik.Windows.Documents.FormatProviders.ReplaceStyleNameHandler.TryGetStyleNamesByStyleName(String displayName, RadDocumentDefaultStyleInfo& defaultStyleInfo)
at Telerik.Windows.Documents.FormatProviders.ReplaceStyleNameHandler.Replace(ReplaceStyleNameContext context)
at Telerik.Windows.Documents.FormatProviders.Rtf.Import.RtfStyleImporter.DoVisitText(RtfText text)
at Telerik.Windows.Documents.FormatProviders.Rtf.Import.RtfElementIteratorBase.VisitElement(RtfElement element, Boolean recursive)
at Telerik.Windows.Documents.FormatProviders.Rtf.Import.RtfElementIteratorBase.VisitGroupChildren(RtfGroup group, Boolean recursive)
at Telerik.Windows.Documents.FormatProviders.Rtf.Import.RtfStyleImporter.ImportStyleGroup(RtfGroup group)
at Telerik.Windows.Documents.FormatProviders.Rtf.Import.RtfStylesTable.FillStyle(RtfGroup group, StyleType type, Boolean isDefault)
at Telerik.Windows.Documents.FormatProviders.Rtf.Import.RtfStylesTable.DoVisitGroup(RtfGroup group)
at Telerik.Windows.Documents.FormatProviders.Rtf.Import.RtfElementIteratorBase.VisitElement(RtfElement element, Boolean recursive)
at Telerik.Windows.Documents.FormatProviders.Rtf.Import.RtfElementIteratorBase.VisitGroupChildren(RtfGroup group, Boolean recursive)
at Telerik.Windows.Documents.FormatProviders.Rtf.Import.RtfStylesTable.ReadTable(RtfGroup group, RtfImportContext context)
at Telerik.Windows.Documents.FormatProviders.Rtf.Import.RtfHandlers.RtfGroupHandlers.StylesTableHandler(RtfGroup group, RtfImportContext context)
at Telerik.Windows.Documents.FormatProviders.Rtf.Import.RtfDocumentImporter.DoVisitGroup(RtfGroup group)
at Telerik.Windows.Documents.FormatProviders.Rtf.Import.RtfElementIteratorBase.VisitElement(RtfElement element, Boolean recursive)
at Telerik.Windows.Documents.FormatProviders.Rtf.Import.RtfElementIteratorBase.VisitGroupChildren(RtfGroup group, Boolean recursive)
at Telerik.Windows.Documents.FormatProviders.Rtf.Import.RtfDocumentImporter.ImportRoot(RtfGroup rtfGroup)
at Telerik.Windows.Documents.FormatProviders.Rtf.Import.RtfDocumentImporter.Import(Stream input, RtfImportSettings settings)
at Telerik.Windows.Documents.FormatProviders.Rtf.RtfFormatProvider.Import(Stream input)
at Telerik.Windows.Documents.FormatProviders.Rtf.RtfFormatProvider.Import(String input)
(PS: The code has been tested with the latest release of UI for WPF)
I don't suppose the RtfFormatProvider has a hidden ConcurrentDictionary somewhere that could solve this? :)
Do you know if what I'm trying to acheive is possible?
