This is a migrated thread and some comments may be shown as answers.

RtfFormatProvider - Thread exception

4 Answers 28 Views
RichTextBox
This is a migrated thread and some comments may be shown as answers.
ELIAS
Top achievements
Rank 2
ELIAS asked on 18 Sep 2018, 04:04 PM

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 Sub
 
Private 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?

4 Answers, 1 is accepted

Sort by
0
Accepted
Boby
Telerik team
answered on 20 Sep 2018, 01:27 PM
Hi Elias,

I can confirm that this is a bug in the implementation. We managed to fix it right away, so if the integration testing goes well, the fix will be published in the next internal build (should be available in your account at the start of next week), as well as in the next official release (R3 2018 SP1, expected in about a month). You can follow the development by following the public item in our feedback portal:
RichTextBox: ArgumentException when importing RTF documents in multiple threads

I have added some Telerik points to your account as a token of appreciation for the bug report.

Regards,
Boby
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
ELIAS
Top achievements
Rank 2
answered on 20 Sep 2018, 03:14 PM

Hello Boby,

 

Thank you for the fix!

I'll be sure to test the release as soon as it's available and report back on the result.

 

Best regards,

Elias

0
ELIAS
Top achievements
Rank 2
answered on 27 Sep 2018, 01:36 PM

Hi,

Sorry for the delay.

I've tested with the internal build and I can confirm that the problem has been fixed!

 

Thank you again.

 

Best regards

0
Boby
Telerik team
answered on 28 Sep 2018, 06:13 AM
Hi Elias, 

Thanks for confirming back. I am glad that the fix is successful.

Don't hesitate to write in the forum or open a support ticket if you spot something problematic, or if you have questions or need help.


Regards,
Boby
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Tags
RichTextBox
Asked by
ELIAS
Top achievements
Rank 2
Answers by
Boby
Telerik team
ELIAS
Top achievements
Rank 2
Share this question
or