IPB

Welcome Guest ( Log In | Register )

 
Reply to this topicStart new topic
> Exceptions with bulk PDF exports
Napokue
post Mar 6 2019, 03:34 AM
Post #1


Newbie
*

Group: Members
Posts: 5
Joined: 6-March 19
Member No.: 65580



Hello,

While doing a bulk conversion of XML => PDF (more than 100 000+ files), I am getting OutOfMemoryException's, ArgumentOutOfRangeException's, IndexOutOfRangeException's, NullReferenceException's. All these exceptions are thrown while doing something with Floats. See the following stacktraces for clarification.

CODE
"ExceptionType":"System.OutOfMemoryException",
"StackTrace":"
at System.Text.StringBuilder.ToString()
at FastReport.Utils.FastString.ToString()
at FastReport.TypeConverters.FloatCollectionConverter.ConvertTo(ITypeDescriptorCont
ext context, CultureInfo culture, Object value, Type destinationType)
at System.ComponentModel.TypeConverter.ConvertToString(ITypeDescriptorContext context, CultureInfo culture, Object value)
at FastReport.Utils.Converter.ToString(Object value)
at FastReport.Utils.FRWriter.WriteValue(String name, Object value)
at FastReport.BandBase.Serialize(FRWriter writer)
at FastReport.DataBand.Serialize(FRWriter writer)
at FastReport.Utils.FRWriter.Write(IFRSerializable obj, Object diff)
at FastReport.Preview.SourcePages.CloneObjects(Base source, Base parent)
at FastReport.Preview.SourcePages.CloneObjects(Base source, Base parent)
at FastReport.Preview.SourcePages.Add(ReportPage page)
at FastReport.Preview.PreparedPages.AddSourcePage(ReportPage page)
at FastReport.Engine.ReportEngine.InitializePages()
at FastReport.Engine.ReportEngine.PrepareToFirstPass(Boolean append)
at FastReport.Engine.ReportEngine.Run(Boolean runDialogs, Boolean append, Boolean resetDataState, ReportPage page)
at FastReport.Engine.ReportEngine.Run(Boolean runDialogs, Boolean append, Boolean resetDataState)
at FastReport.Report.Prepare(Boolean append)
at FastReport.Report.Prepare()


CODE
"ExceptionMessage":"Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: chunkLength","
"ExceptionType":"System.ArgumentOutOfRangeException",
"StackTrace":"
at System.Text.StringBuilder.ToString()
at FastReport.Utils.FastString.ToString()
at FastReport.TypeConverters.FloatCollectionConverter.ConvertTo(ITypeDescriptorCont
ext context, CultureInfo culture, Object value, Type destinationType)
at System.ComponentModel.TypeConverter.ConvertToString(ITypeDescriptorContext context, CultureInfo culture, Object value)
at FastReport.Utils.Converter.ToString(Object value)
at FastReport.Utils.FRWriter.WriteValue(String name, Object value)
at FastReport.BandBase.Serialize(FRWriter writer)
at FastReport.DataBand.Serialize(FRWriter writer)
at FastReport.Utils.FRWriter.Write(IFRSerializable obj, Object diff)
at FastReport.Preview.SourcePages.CloneObjects(Base source, Base parent)
at FastReport.Preview.SourcePages.CloneObjects(Base source, Base parent)
at FastReport.Preview.SourcePages.Add(ReportPage page)
at FastReport.Preview.PreparedPages.AddSourcePage(ReportPage page)
at FastReport.Engine.ReportEngine.InitializePages()
at FastReport.Engine.ReportEngine.PrepareToFirstPass(Boolean append)
at FastReport.Engine.ReportEngine.Run(Boolean runDialogs, Boolean append, Boolean resetDataState, ReportPage page)
at FastReport.Engine.ReportEngine.Run(Boolean runDialogs, Boolean append, Boolean resetDataState)
at FastReport.Report.Prepare(Boolean append)
at FastReport.Report.Prepare()


CODE
"ExceptionMessage":"Index was outside the bounds of the array.",
"ExceptionType":"System.IndexOutOfRangeException",
"StackTrace":"
at System.Text.StringBuilder.Append(Char value, Int32 repeatCount)
at FastReport.Utils.FastString.Clear()
at FastReport.TypeConverters.FloatCollectionConverter.ConvertTo(ITypeDescriptorCont
ext context, CultureInfo culture, Object value, Type destinationType)
at System.ComponentModel.TypeConverter.ConvertToString(ITypeDescriptorContext context, CultureInfo culture, Object value)
at FastReport.Utils.Converter.ToString(Object value)
at FastReport.Utils.FRWriter.WriteValue(String name, Object value)
at FastReport.ReportPage.Serialize(FRWriter writer)
at FastReport.Utils.FRWriter.Write(IFRSerializable obj, Object diff)
at FastReport.Preview.SourcePages.CloneObjects(Base source, Base parent)
at FastReport.Preview.SourcePages.Add(ReportPage page)
at FastReport.Preview.PreparedPages.AddSourcePage(ReportPage page)
at FastReport.Engine.ReportEngine.InitializePages()
at FastReport.Engine.ReportEngine.PrepareToFirstPass(Boolean append)
at FastReport.Engine.ReportEngine.Run(Boolean runDialogs, Boolean append, Boolean resetDataState, ReportPage page)
at FastReport.Engine.ReportEngine.Run(Boolean runDialogs, Boolean append, Boolean resetDataState)
at FastReport.Report.Prepare(Boolean append)
at FastReport.Report.Prepare()


CODE
"ExceptionMessage":"Object reference not set to an instance of an object.",
"ExceptionType":"System.NullReferenceException",
"StackTrace":"
at FastReport.Utils.FloatCollection.Assign(FloatCollection source)
at FastReport.BandBase.Assign(Base source)
at FastReport.DataBand.Assign(Base source)
at FastReport.Preview.Dictionary.DictionaryItem.CloneObject(String alias)
at FastReport.Preview.Dictionary.GetObject(String name)
at FastReport.Preview.PreparedPage.ReadObject(Base parent, XmlItem item, Boolean readChildren, FRReader reader)
at FastReport.Preview.PreparedPage.ReadPage(Base parent, XmlItem item, Boolean readchild, FRReader reader)
at FastReport.Preview.PreparedPage.StartGetPage(Int32 index)
at FastReport.Export.ExportBase.ExportPageNew(Int32 pageNo)
at FastReport.Export.ExportBase.Export(Report report, Stream stream)
at FastReport.Report.Export(ExportBase export, Stream stream)


CODE
"ExceptionMessage":"StartIndex cannot be less than zero.
Parameter name startIndex",
"ExceptionType":"System.ArgumentOutOfRangeException",
"StackTrace":"
at System.Text.StringBuilder.Remove(Int32 startIndex, Int32 length)
at FastReport.Utils.FastString.Remove(Int32 startIndex, Int32 length)
at FastReport.TypeConverters.FloatCollectionConverter.ConvertTo(ITypeDescriptorCont
ext context, CultureInfo culture, Object value, Type destinationType)
at System.ComponentModel.TypeConverter.ConvertToString(ITypeDescriptorContext context, CultureInfo culture, Object value)
at FastReport.Utils.Converter.ToString(Object value)
at FastReport.Utils.FRWriter.WriteValue(String name, Object value)
at FastReport.BandBase.Serialize(FRWriter writer)
at FastReport.DataBand.Serialize(FRWriter writer)
at FastReport.Utils.FRWriter.Write(IFRSerializable obj, Object diff)
at FastReport.Preview.SourcePages.CloneObjects(Base source, Base parent)
at FastReport.Preview.SourcePages.CloneObjects(Base source, Base parent)
at FastReport.Preview.SourcePages.Add(ReportPage page)
at FastReport.Preview.PreparedPages.AddSourcePage(ReportPage page)
at FastReport.Engine.ReportEngine.InitializePages()
at FastReport.Engine.ReportEngine.PrepareToFirstPass(Boolean append)
at FastReport.Engine.ReportEngine.Run(Boolean runDialogs, Boolean append, Boolean resetDataState, ReportPage page)
at FastReport.Engine.ReportEngine.Run(Boolean runDialogs, Boolean append, Boolean resetDataState)
at FastReport.Report.Prepare(Boolean append)
at FastReport.Report.Prepare()


My initial thoughts about this is that this specific class is not multithreading friendly. It looks like race conditions. I greatly appreciate it if someone has some kind of direction to steer me to for fixing this problem.
Go to the top of the page
 
+Quote Post
ipong
post Mar 6 2019, 05:32 AM
Post #2


Advanced Member
***

Group: Members
Posts: 410
Joined: 11-July 14
Member No.: 60089



https://www.fast-report.com/en/forum/index....hl=showprogress
Go to the top of the page
 
+Quote Post
Napokue
post Mar 6 2019, 06:56 AM
Post #3


Newbie
*

Group: Members
Posts: 5
Joined: 6-March 19
Member No.: 65580



Unfortunately this is not the solution, I already have turned off all dialogs.
Go to the top of the page
 
+Quote Post
ipong
post Mar 6 2019, 07:23 AM
Post #4


Advanced Member
***

Group: Members
Posts: 410
Joined: 11-July 14
Member No.: 60089



did you use preview control? try to export fastreport directly
Go to the top of the page
 
+Quote Post
Napokue
post Mar 6 2019, 08:10 AM
Post #5


Newbie
*

Group: Members
Posts: 5
Joined: 6-March 19
Member No.: 65580



I am not using the preview control, I am directly using the Fast Report code via the Report class and the PdfExport class. So that would not be it. I think that there are problems with the FloatConverter and the FastString classes.
Go to the top of the page
 
+Quote Post
ipong
post Mar 6 2019, 09:03 AM
Post #6


Advanced Member
***

Group: Members
Posts: 410
Joined: 11-July 14
Member No.: 60089



i think this is dotnet framework problem, try to force garbage collector => GC.Collect()

https://stackoverflow.com/questions/1733667...emory-exception
Go to the top of the page
 
+Quote Post
Napokue
post Mar 23 2019, 12:44 PM
Post #7


Newbie
*

Group: Members
Posts: 5
Joined: 6-March 19
Member No.: 65580



I have made a custom implementation of the FloatCollectionConverter in the Fast Report code. I have send an email to Fast Report but unfortunately I do not have an answer yet. So I'll be posting the code for the time being.

CODE
  internal class FloatCollectionConverter : TypeConverter
  {
    public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
    {
      if (sourceType == typeof (string))
        return true;
      return base.CanConvertFrom(context, sourceType);
    }

    public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType)
    {
      if (destinationType == typeof (string))
        return true;
      return base.CanConvertTo(context, destinationType);
    }

    public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
    {
      if (!(value is string))
        return base.ConvertFrom(context, culture, value);
      FloatCollection floatCollection = new FloatCollection();
      string str1 = value as string;
      char[] chArray = new char[1]{ ',' };
      foreach (string str2 in str1.Split(chArray))
        floatCollection.Add((float) Converter.FromString(typeof (float), str2));
      return (object) floatCollection;
    }

      public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
      {
          if (!(destinationType == typeof(string)))
              return base.ConvertTo(context, culture, value, destinationType);
          if (value == null)
              return string.Empty;
          return string.Join(",", (value as FloatCollection).Cast<float>().Select(f => Converter.ToString(f)));
      }
  }


Reason why it caused all these exceptions was because the StringBuilder was declared and initialized once and due to multi threading it was written and read to at the same time.
Go to the top of the page
 
+Quote Post
v2afrank
post Mar 27 2019, 12:00 AM
Post #8


Advanced Member
***

Group: Members
Posts: 33
Joined: 9-August 05
Member No.: 2298



I got an OutofMemory Exception during bulk export too ?
Maybe it is the same problem. How can I use your code ?
Go to the top of the page
 
+Quote Post
Napokue
post Mar 28 2019, 04:10 AM
Post #9


Newbie
*

Group: Members
Posts: 5
Joined: 6-March 19
Member No.: 65580



@v2afrank If you have the Fast Report source available, you can copy and paste this snippet in: FastReport/TypeConverters/FloatCollectionConverter.cs. The reason you get this exception is because there is a global Stringbuilder that is only initialized once and will cause a OutOfMemoryException.

I hope this will fix it for you.
Go to the top of the page
 
+Quote Post
v2afrank
post May 20 2019, 07:20 AM
Post #10


Advanced Member
***

Group: Members
Posts: 33
Joined: 9-August 05
Member No.: 2298



Sorry for the late answer. No, I don't have the source code. I created a ticket at the support. Mybi this help ?
Go to the top of the page
 
+Quote Post

Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 



- Time is now: 20th June 2019 - 01:23 PM