Concurrency problem in ExportDocument

Stimulsoft Reports.NET discussion
Post Reply
insertusername
Posts: 3
Joined: Wed Jul 03, 2024 8:10 am

Concurrency problem in ExportDocument

Post 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;
    }
Lech Kulikowski
Posts: 7333
Joined: Tue Mar 20, 2018 5:34 am

Re: Concurrency problem in ExportDocument

Post by Lech Kulikowski »

Hello,

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

Thank you.
insertusername
Posts: 3
Joined: Wed Jul 03, 2024 8:10 am

Re: Concurrency problem in ExportDocument

Post 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;
    }
Max Shamanov
Posts: 990
Joined: Tue Sep 07, 2021 10:11 am

Re: Concurrency problem in ExportDocument

Post 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.
insertusername
Posts: 3
Joined: Wed Jul 03, 2024 8:10 am

Re: Concurrency problem in ExportDocument

Post by insertusername »

Sample Projekt added.
Attachments
ConcurrencyErrorSample.zip
(102.46 KiB) Downloaded 406 times
Max Shamanov
Posts: 990
Joined: Tue Sep 07, 2021 10:11 am

Re: Concurrency problem in ExportDocument

Post 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
Max Shamanov
Posts: 990
Joined: Tue Sep 07, 2021 10:11 am

Re: Concurrency problem in ExportDocument

Post by Max Shamanov »

Hello.

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

Thank you.
Post Reply