We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

RemoveEmptyGroup property throws exception if there is a list with length = 0

I am using nested lists with MergeFields and I use StartTables / EndTables tags to display those values. Within those tags there is other fields and I want to remove all info between the two tags if the list has no items. I stumbled upon the RemoveEmptyGroup property and set it to true. 

This gives me the following error:

{"ClassName":"System.ArgumentOutOfRangeException","Message":"Index was out of range. Must be non-negative and less than the size of the collection.","Data":null,"InnerException":null,"HelpURL":null,"StackTraceString":"   at System.Collections.Generic.List`1.System.Collections.IList.get_Item(Int32 index)\r   at Syncfusion.DocIO.DLS.EntityCollection.get_Item(Int32 index)\r   at Syncfusion.DocIO.DLS.MailMerge.EmptyGroupInTable(GroupSelector gs)\r   at Syncfusion.DocIO.DLS.MailMerge.EmptyGroup(GroupSelector gs)\r   at Syncfusion.DocIO.DLS.MailMerge.OnGroupFound(IRowsEnumerator rowsEnum)\r   at Syncfusion.DocIO.DLS.MailMerge.GroupSelector.FindInBodyItemsInNested(BodyItemCollection bodyItems, Int32 itemStart, Int32 itemEnd)\r   at Syncfusion.DocIO.DLS.MailMerge.ExecuteGroupForSelection(WTextBody textBody, Int32 itemStart, Int32 itemEnd, Int32 pItemStart, Int32 pItemEnd, IRowsEnumerator rowsEnum)\r   at Syncfusion.DocIO.DLS.MailMerge.ExecuteGroupForRowSelection(WTable table, Int32 startRowIndex, Int32 count, IRowsEnumerator rowsEnum)\r   at Syncfusion.DocIO.DLS.MailMerge.ExecuteGroupForSelection(WTextBody textBody, Int32 itemStart, Int32 itemEnd, Int32 pItemStart, Int32 pItemEnd, IRowsEnumerator rowsEnum)\r   at Syncfusion.DocIO.DLS.MailMerge.OnBodyGroupFound(IRowsEnumerator rowsEnum)\r   at Syncfusion.DocIO.DLS.MailMerge.GroupSelector.FindInBodyItems(BodyItemCollection bodyItems)\r   at Syncfusion.DocIO.DLS.MailMerge.ExecuteGroup(WSection section, IRowsEnumerator rowsEnum)\r   at Syncfusion.DocIO.DLS.MailMerge.ExecuteNestedGroup(String tableName)\r   at Syncfusion.DocIO.DLS.MailMerge.ExecuteNestedGroup(MailMergeDataTable dataTable)\r   at 
<DELETED PART>
","RemoteStackTraceString":null,"RemoteStackIndex":0,"ExceptionMethod":null,"HResult":-2146233086,"Source":"System.Private.CoreLib","WatsonBuckets":null,"ParamName":"index","ActualValue":null}

This exception is only thrown if at least one of the lists has length = 0, but not if all lists have at least a length of 1. Is this a bug or can someone lead me into the right direction on how to solve this? If I set RemoveEmptyGroup = false the code works, but I have leftover text between the  StartTables / EndTables tags.

Obviously I am also happy to hear other solutions on how I can not render anything in between StartTables / EndTables tags if the list is 0. :-)



2 Replies

AN Anto Nihil Sahaya Raj Syncfusion Team October 20, 2022 09:00 AM

Hi Nino Müller,

We have tried to reproduce the reported problem using the given details, but it works properly at our end. For your reference, we have attached the sample application which we tried to reproduce the reported problem at our end. We suggest you to try the attached sample at your end.

Could you please try the same sample application at your end and provide us confirmation whether you are facing issues in this simple sample too.

If the issue is not reproduced using the attached sample application at your end, then could you please modify the attached sample as an issue-reproducible sample application and share us. Thereby, we will proceed further to replicate the same problem at our end and
will provide you appropriate solution at the earliest.

Regards,
Anto Nihil S


Attachment: Removeemptymergefieldgroups_e61cde71.zip


NI nino.mueller October 20, 2022 10:32 AM

Thanks so much, the attached project helped a bit to narrow it down and we figured out what caused the exception. In our Word document we reused a group. You can reproduce the exception if you add a second Empoyees Group tag, then the exception is thrown. I guess this is not a bug, but me using the tags wrong. I will just add the same data structure a second time with a different group name.


Loader.
Live Chat Icon For mobile
Up arrow icon