Spire.Doc is a professional Word .NET library specifically designed for developers to create, read, write, convert and print Word document files. Get free and professional technical support for Spire.Doc for .NET, Java, Android, C++, Python.

Mon May 30, 2016 7:01 pm

Hello,

We are getting this error ONLY in our prod environment, we do the same thing with the same document in QA and it work fine.

The prod server and the QA server both use the Spire.Doc.Dll version 5.6.62.3040.

But I cannot guaranty the no other version of the file are present on the prod server (as example in backup folder), but the reference in the project is pointing to the 5.6.62.3040 version.

Here is the code which trigger the error (and below the error and stacktrace) :

Code: Select all
Spire.Doc.Document document = new Spire.Doc.Document();

         System.IO.MemoryStream inputStream = new System.IO.MemoryStream(bytes);
         document.LoadFromStream(inputStream, Spire.Doc.FileFormat.Auto);
         
         Variable AdminURL = variables.Where(x => x.Name == (new Variables()).AdminURL.Name).FirstOrDefault();
         if(AdminURL != null) AdminURL.Value = Settings.AdminURL;

         Variable PortalURL = variables.Where(x => x.Name == (new Variables()).PortalURL.Name).FirstOrDefault();
         if (PortalURL != null) PortalURL.Value = Settings.PortalURL;

         foreach (Variable replacer in variables)
         {
            if (replacer.Value != null || replaceNullMarkersWithBlank)
            {
               if (replacer.Value == null) replacer.Value = string.Empty;
               document.Replace("[[" + replacer.Name + "]", replacer.Value.ToFUCOnlyFirst(), false, false);
               document.Replace("[" + replacer.Name + "]", replacer.Value, false, false);
            }

         }
         
         System.Text.RegularExpressions.Regex regex = new System.Text.RegularExpressions.Regex(UrlFinder);
         System.Text.RegularExpressions.MatchCollection matches = regex.Matches(document.GetText());
         if (matches != null)
         {
            foreach (System.Text.RegularExpressions.Match match in matches)
            {
               string[] parts = match.Value.Replace("{", "").Replace("}","").Split(',');
               if (parts.Length == 2)
               {
                  string text = parts[0].Trim();
                  string url = parts[1].Trim();
                  if (!string.IsNullOrWhiteSpace(text) && !string.IsNullOrWhiteSpace(url))
                  {
                     Spire.Doc.Documents.TextSelection ts = document.FindString(match.Value, false, false);
                     if (ts != null)
                     {
                        Spire.Doc.Fields.TextRange tr = ts.GetAsOneRange();
                        int index = tr.OwnerParagraph.ChildObjects.IndexOf(tr);

                        Spire.Doc.Fields.Field field = new Spire.Doc.Fields.Field(document);
                        field.Code = "HYPERLINK \"" + url + "\"";
                        field.Type = Spire.Doc.FieldType.FieldHyperlink;

                        tr.OwnerParagraph.ChildObjects.Insert(index, field);

                        Spire.Doc.Fields.FieldMark fm = new Spire.Doc.Fields.FieldMark(document, Spire.Doc.Documents.FieldMarkType.FieldSeparator);
                        tr.OwnerParagraph.ChildObjects.Insert(index + 1, fm);

                        Spire.Doc.Fields.TextRange textR = new Spire.Doc.Fields.TextRange(document);
                        textR.Text = text;
                        textR.CharacterFormat.TextColor = System.Drawing.Color.Blue;
                        textR.CharacterFormat.UnderlineStyle = Spire.Doc.Documents.UnderlineStyle.Single;
                        tr.OwnerParagraph.ChildObjects.Insert(index + 2, textR);

                        Spire.Doc.Fields.FieldMark fmend = new Spire.Doc.Fields.FieldMark(document, Spire.Doc.Documents.FieldMarkType.FieldEnd);
                        tr.OwnerParagraph.ChildObjects.Insert(index + 3, fmend);

                        field.End = fmend;
                        tr.OwnerParagraph.ChildObjects.RemoveAt(index + 4);
                     }
                  }
               }
            }
         }

         System.IO.MemoryStream outputStream = new System.IO.MemoryStream();
         Spire.Doc.FileFormat format = document.DetectedFormatType;
         if (convertToPDF) format = Spire.Doc.FileFormat.PDF;
         document.SaveToStream(outputStream, format);
         document.Dispose();


Index was outside the bounds of the array. at Spire.Doc.Fields.Field.Spire.Doc.Layout.IDocumentWidget.Measure(spr⃪ dc)
at spr₡.ᜀ(RectangleF A_0)
at spr᥵.ᜃ(spr⋖ A_0)
at spr᥵.ᜀ(RectangleF A_0)
at sprṖ.ᜃ(spr⋖ A_0)
at spr᥵.ᜀ(RectangleF A_0)
at spr᥵.ᜃ(spr⋖ A_0)
at spr᥵.ᜀ(RectangleF A_0)
at sprហ.ᜀ(spr᝾ A_0, sprẾ A_1, spr⃪ A_2)
at spr᳇.ᜋ()
at spr᳇.ᜑ()
at spr᳇.ᜁ(IDocument A_0)
at spr᧹.ᜀ(Document A_0)
at Spire.Doc.Document.ᜀ(Stream A_0)
at Spire.Doc.Document.SaveToFile(Stream stream, FileFormat fileFormat)
at OIQ.Inspection2016.Services.Service.FuzionWord(Byte[] bytes, List`1 variables, Boolean convertToPDF, Boolean replaceNullMarkersWithBlank)
at OIQ.Inspection2016.Services.Service.FuzionWord(Byte[] bytes, List`1 variables, Boolean convertToPDF)
at OIQ.Inspection2016.Web.Controllers.BaseController.GetFileByDocumentId(Guid id)
at lambda_method(Closure , ControllerBase , Object[] )
at System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters)
at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters)

Thanks,
Robin Leblond
.Net Consultant, Montréal, Qc, Canada

robinleblond
 
Posts: 22
Joined: Fri Jan 29, 2016 5:46 pm

Tue May 31, 2016 2:37 am

Hi,

Thanks for your posting.
Do you want to search some certain text and change them as hyperlinks?
If so, please try the following solution to change plain text to hyperlinks.
Code: Select all
//Find the text which will be added hyperlink
            TextSelection[] selections = document.FindAllString("https://www.google.com",true,true);
            //Get the text'textRange
            TextRange range=selections[0].GetAsOneRange();
            Paragraph  p=range.OwnerParagraph;
            //Get the index of the textrange
            int index= p.Items.IndexOf(range);
            //Remove the text
            p.Items.Remove(range);
           //Add a hyperlink and its uri is "https://www.google.com", and then add the hyperlink to the current paragraph
            Field field = new Field(document);
            field.Type = FieldType.FieldHyperlink;
            Hyperlink hyperlink = new Hyperlink(field);
            hyperlink.Type = HyperlinkType.WebLink;
            hyperlink.Uri = "https://www.google.com";
            p.Items.Insert(index, field);

            IParagraphBase start = document.CreateParagraphItem(ParagraphItemType.FieldMark);
            (start as FieldMark).Type = FieldMarkType.FieldSeparator;
            p.Items.Insert(index + 1, start);

            ITextRange textRange = new TextRange(document);
            textRange.Text = "https://www.google.com";
            textRange.CharacterFormat.TextColor = System.Drawing.Color.Blue;
            textRange.CharacterFormat.UnderlineStyle = UnderlineStyle.Single;
            p.Items.Insert(index + 2, textRange);

            IParagraphBase end = document.CreateParagraphItem(ParagraphItemType.FieldMark);
            (end as FieldMark).Type = FieldMarkType.FieldEnd;
            p.Items.Insert(index + 3, end);
           
            //Save as docx document
            document.SaveToFile("sample.docx",FileFormat.Docx);


If the above solution doesn't help you, to help us replicate your issue soon and work out solution, please share your original document and whole testing code, and also tell us detail operation system information about your prod environment. You can also send it to support@e-iceblue.com if it is inconvenience to share here.

Thank you for further assistance.

Best Regards,
Amy
E-iceblue support team
User avatar

amy.zhao
 
Posts: 2766
Joined: Wed Jun 27, 2012 8:50 am

Tue May 31, 2016 12:29 pm

Amy, in this case, the original document doesn't contain any link replacement, so no. And this bug happen only with this one document, while all others (hundred of them) are working fine. I will send the document and this case to the support. Thanks.
Robin Leblond
.Net Consultant, Montréal, Qc, Canada

robinleblond
 
Posts: 22
Joined: Fri Jan 29, 2016 5:46 pm

Wed Jun 01, 2016 3:27 am

Dear Robin,

Thanks for providing your document.
Your incomplete code(in e-mail and in forum) cannot help us replicate and investigate your issue.
Please provide us complete code can directly run to replicate your issue, and tell us detail operation system information about your prod environment.
Thank you for further assistance again.

Best Regards,
Amy
E-iceblue support team
User avatar

amy.zhao
 
Posts: 2766
Joined: Wed Jun 27, 2012 8:50 am

Mon Feb 20, 2017 2:28 pm

Was there any solution to your specific problem Robin?

We are having a similar issue; searching/replacing in a document works fine for a lot of data (customers in our case), but one specific set of data gives this error when saving the document:

Index was outside the bounds of the array.
at Spire.Doc.Fields.Field.Spire.Doc.Layout.IDocumentWidget.Measure(spr⃯ dc)
at spr₦.ᜀ(RectangleF A_0)
at spr᥻.ᜄ(spr⋙ A_0)
at spr᥻.ᜀ(RectangleF A_0)
at sprṕ.ᜄ(spr⋙ A_0)
at spr᥻.ᜀ(RectangleF A_0)
at spr᥻.ᜄ(spr⋙ A_0)
at spr᥻.ᜀ(RectangleF A_0)
at sprហ.ᜀ(sprក A_0, sprẻ A_1, spr⃯ A_2)
at spr᳇.ᜋ()
at spr᳇.ᜒ()
at spr᳇.ᜁ(IDocument A_0)
at spr᧾.ᜀ(Document A_0)
at Spire.Doc.Document.ᜀ(Stream A_0)
at Spire.Doc.Document.SaveToFile(Stream stream, FileFormat fileFormat)

onlinetools
 
Posts: 1
Joined: Wed May 11, 2016 7:54 am

Tue Feb 21, 2017 2:43 am

Dear onlinetools,

Thanks for your inquiry.
It is difficult to say what the reason causes the issue if we cannot reproduce your issue. And different sample file may has different reason caused the issue. So please share us your sample files and complete code here, or you can send it to us(support@e-iceblue.com) via email, so that we can reproduce the issue and investigate it quickly. And we promise to keep it confidential and won’t use it for any other purpose.

Many thanks,
Betsy
E-iceblue support team
User avatar

Betsy.jiang
 
Posts: 3099
Joined: Tue Sep 06, 2016 8:30 am

Mon Apr 19, 2021 7:33 am

Hi,
we get the same error occurred during request execution, the error is: Index was outside the bounds of the array (details below) while generating the * .docx file.
We use the Spire.Doc.Dll version 8.12.14.4040.

I found one of the solutions on the forum suggesting a problem with hyperlink, but in our case it does not apply (no hyperlinks in *.docx file)

Here is the code which trigger the error (and below the error details) :
Code:
Code: Select all
document.SaveToStream(outputStream, FileFormat.Docx2013);


Error details:
Code: Select all
Error occurred during request execution, the error is: Index was outside the bounds of the array. at sprឤ.ᜀ(sprឋ A_0, String A_1) at sprឤ.ᜄ() at sprឤ.ᜀ(RectangleF A_0) at sprឡ.ᜋ(sprហ A_0) at sprឡ.ᜁ(RectangleF A_0) at sprអ.ᜂ(sprហ A_0) at sprឡ.ᜁ(RectangleF A_0) at sprឡ.ᜋ(sprហ A_0) at sprឡ.ᜁ(RectangleF A_0) at sprឡ.ᜋ(sprហ A_0) at sprឡ.ᜁ(RectangleF A_0) at sprប.ᜀ(sprដ A_0, sprង A_1, sprᰊ A_2) at sprᰂ.ᜒ() at sprᰂ.ᜓ() at sprᰂ.ᜀ(Document A_0, List`1 A_1) at Spire.Doc.Document.ᜀ(List`1 A_0) at dbbrowser_reporting.lib.docx.DocxGenerator.GenerateDocx() at dbbrowser_reporting.lib.docx.AnomalyReportDocxGenerator.Generate() at dbbrowser_reporting.json.file_data.Page_Load(Object sender, EventArgs e)

przemyslaw
 
Posts: 1
Joined: Fri Apr 09, 2021 2:22 pm

Mon Apr 19, 2021 8:55 am

Hello,

Thanks for your inquiry!

To help us reproduce and investigate your issue quickly and efficiently, please provide us with the following information for reference. To protect your private, you can send it to us via email (support@e-iceblue.com). Thanks in advance!

1. Your input file (if any)
2. Your testing code
3. Your target framework
4. Your system information (E.g. Win7, 64 bit) and region setting (E.g. China, Chinese)

Sincerely,
Marcia
E-iceblue support team
User avatar

Marcia.Zhou
 
Posts: 858
Joined: Wed Nov 04, 2020 2:29 am

Thu May 06, 2021 7:29 am

Hello,

Hope you are doing well!

How is the issue now? If it still exists, could you please provide the above information to us for further investigation?

Thanks in advance.

Sincerely,
Marcia
E-iceblue support team
User avatar

Marcia.Zhou
 
Posts: 858
Joined: Wed Nov 04, 2020 2:29 am

Mon Jul 05, 2021 8:35 am

Hello, we're experiencing the same issue on this topic-.

System.IndexOutOfRangeException: Index was outside the bounds of the array.
at sprឣ.ᜄ()
at sprឣ.ᜊ()
at sprឣ.ᜀ(RectangleF A_0)
at sprស.ᜋ(sprឞ A_0)
at sprស.ᜁ(RectangleF A_0)
at sprស.ᜋ(sprឞ A_0)
at sprស.ᜁ(RectangleF A_0)
at sprន.ᜀ(sprឋ A_0, sprច A_1, spr᯶ A_2)
at sprᯮ.ᜒ()
at sprᯮ.ᜓ()
at sprᯮ.ᜀ(IDocument A_0)
at sprᰙ.ᜀ(Document A_0)
at Spire.Doc.Document.ᜁ(Stream A_0)
at Spire.Doc.Document.SaveToFile(Stream stream, FileFormat fileFormat)
at Spire.Doc.Document.SaveToStream(Stream stream, FileFormat fileFormat)
at Etrel.Puffer.Invoicing.InvoiceGenerator.GenerateInvoice(InvoiceDetail invoice, Byte[] file, FileForUpload& pdf) in C:\builds\aHsRyz3D\0\ocean\main\Puffer\Etrel.Puffer.Invoicing\InvoiceGenerator.cs:line 311 System.IndexOutOfRangeException: Index was outside the bounds of the array.
at sprឣ.ᜄ()
at sprឣ.ᜊ()
at sprឣ.ᜀ(RectangleF A_0)
at sprស.ᜋ(sprឞ A_0)
at sprស.ᜁ(RectangleF A_0)
at sprស.ᜋ(sprឞ A_0)
at sprស.ᜁ(RectangleF A_0)
at sprន.ᜀ(sprឋ A_0, sprច A_1, spr᯶ A_2)
at sprᯮ.ᜒ()
at sprᯮ.ᜓ()
at sprᯮ.ᜀ(IDocument A_0)
at sprᰙ.ᜀ(Document A_0)
at Spire.Doc.Document.ᜁ(Stream A_0)
at Spire.Doc.Document.SaveToFile(Stream stream, FileFormat fileFormat)
at Spire.Doc.Document.SaveToStream(Stream stream, FileFormat fileFormat)

Can you help us with the resolution?

ziga.jelen
 
Posts: 1
Joined: Wed Apr 28, 2021 1:32 pm

Mon Jul 05, 2021 9:35 am

Hello Ziga,

Thanks for your inquiry.
In order to help us investigate and solve your problem quickly and effectively, please provide the following information for our reference. You could attach them here or send to us via email (support@e-iceblue.com). Thanks in advance.
1) Your input file
2) Your test code
3) Your test environment, such as OS info (E.g. Windows7, 64bit) and region setting (E.g. China, Chinese)
4) Your application type, such as Console app (.NET Framework 4.5)

Sincerely,
Annika
E-iceblue support team
User avatar

Annika.Zhou
 
Posts: 1643
Joined: Wed Apr 07, 2021 2:50 am

Return to Spire.Doc