Page 1 of 1

Concurrency problem in ExportDocument

Posted: Wed Jul 03, 2024 8:19 am
by insertusername
We are experiencing exceptions when calling StiReport.ExportDocument. There seems to be an issue loading fonts regarding thread-safety. Locking CreateReport solves this issue, but is not a preferred solution. We are using Stimulsoft.Reports.Engine.NetCore 2024.3.1
Previous versions work fine.

Exception:

Code: Select all

System.AggregateException: One or more errors occurred. (Exception in PdfFonts.GetFontMetrics, font 'Arial' step #50: 'Operations that change non-concurrent collections must have exclusive access. A concurrent update was performed on this collection and corrupted its state. The collection's state is no longer correct.') (Exception in PdfFonts.GetFontMetrics, font 'Arial' step #50: 'Operations that change non-concurrent collections must have exclusive access. A concurrent update was performed on this collection and corrupted its state. The collection's state is no longer correct.') (Exception in PdfFonts.GetFontMetrics, font 'Arial' step #50: 'Operations that change non-concurrent collections must have exclusive access. A concurrent update was performed on this collection and corrupted its state. The collection's state is no longer correct.') (Exception in PdfFonts.GetFontMetrics, font 'Arial' step #50: 'Operations that change non-concurrent collections must have exclusive access. A concurrent update was performed on this collection and corrupted its state. The collection's state is no longer correct.') (Exception in PdfFonts.GetFontMetrics, font 'Arial' step #50: 'Operations that change non-concurrent collections must have exclusive access. A concurrent update was performed on this collection and corrupted its state. The collection's state is no longer correct.')
 ---> System.Exception: Exception in PdfFonts.GetFontMetrics, font 'Arial' step #50: 'Operations that change non-concurrent collections must have exclusive access. A concurrent update was performed on this collection and corrupted its state. The collection's state is no longer correct.'
   at Stimulsoft.Report.Export.PdfFonts.GetFontMetrics(Font font, PdfFontInfo currentFontInfo, UInt16[] glyphMap, Boolean isWpf)
   at Stimulsoft.Report.Export.PdfFonts.InitFontsData(Boolean isWpf)
   at Stimulsoft.Report.Export.StiPdfExportService.ExportPdf1(StiReport report, Stream stream, StiPdfExportSettings settings)
   at Stimulsoft.Report.Export.StiPdfExportService.ExportPdf(StiReport report, Stream stream, StiPdfExportSettings settings)
   at Stimulsoft.Report.StiReport.ExportDocument(StiExportFormat exportFormat, StiExportService exportService, Stream stream, StiExportSettings settings)
   at Stimulsoft.Report.StiReport.ExportDocument(StiExportFormat exportFormat, Stream stream, StiExportSettings settings)
   at Program.CreateReport() in C:\Dev\lnb_new\backend\src\ConsoleApp1\Program.cs:line 47
Repro code:

Code: Select all

public static void Main(string[] args)
    {
        var tasks = new List<Task>
        {
            Task.Factory.StartNew(CreateReport),
            Task.Factory.StartNew(CreateReport),
            Task.Factory.StartNew(CreateReport),
            Task.Factory.StartNew(CreateReport),
            Task.Factory.StartNew(CreateReport)
        };

        Task.WaitAll(tasks.ToArray());
        Console.WriteLine("Done!");
    }

    private static Task CreateReport()
    {
        StiLicense.Key = _licenseKey;
        StiOptions.Export.Pdf.CreatorString = "Stimulsoft";

        var template = File.ReadAllBytes("Report.mrt");
        var report = new StiReport();
        report.Load(template);
        var memoryStream = new MemoryStream();
        report.Render(false);
        var settings = new StiPdfExportSettings { PdfComplianceMode = StiPdfComplianceMode.A1 };
        report.ExportDocument(StiExportFormat.Pdf, memoryStream, settings);
        memoryStream.Seek(0, SeekOrigin.Begin);

        return Task.CompletedTask;
    }

Re: Concurrency problem in ExportDocument

Posted: Wed Jul 03, 2024 9:29 pm
by Lech Kulikowski
Hello,

Please send us a sample project that reproduces the issue for analysis.

Thank you.

Re: Concurrency problem in ExportDocument

Posted: Tue Jul 09, 2024 1:09 pm
by insertusername
Hello

I added a sample in my initial question. do you need additional informations?

Code: Select all

public static void Main(string[] args)
    {
        var tasks = new List<Task>
        {
            Task.Factory.StartNew(CreateReport),
            Task.Factory.StartNew(CreateReport),
            Task.Factory.StartNew(CreateReport),
            Task.Factory.StartNew(CreateReport),
            Task.Factory.StartNew(CreateReport)
        };

        Task.WaitAll(tasks.ToArray());
        Console.WriteLine("Done!");
    }

    private static Task CreateReport()
    {
        StiLicense.Key = _licenseKey;
        StiOptions.Export.Pdf.CreatorString = "Stimulsoft";

        var template = File.ReadAllBytes("Report.mrt");
        var report = new StiReport();
        report.Load(template);
        var memoryStream = new MemoryStream();
        report.Render(false);
        var settings = new StiPdfExportSettings { PdfComplianceMode = StiPdfComplianceMode.A1 };
        report.ExportDocument(StiExportFormat.Pdf, memoryStream, settings);
        memoryStream.Seek(0, SeekOrigin.Begin);

        return Task.CompletedTask;
    }

Re: Concurrency problem in ExportDocument

Posted: Tue Jul 09, 2024 1:55 pm
by Max Shamanov
Hello,

Please send us a sample project that we can run to reproduce the issue on our side for analysis.

Thank you.

Re: Concurrency problem in ExportDocument

Posted: Wed Jul 10, 2024 2:14 pm
by insertusername
Sample Projekt added.

Re: Concurrency problem in ExportDocument

Posted: Thu Jul 11, 2024 2:03 pm
by Max Shamanov
Hello,

We require more time to investigate the issue thoroughly.
Rest assured, we will keep you informed about the outcome as soon as possible.

Thank you.
#14879

Re: Concurrency problem in ExportDocument

Posted: Tue Jul 16, 2024 8:39 am
by Max Shamanov
Hello.

We have made an improvement.
Please, check our next build when it will be available.

Thank you.