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,