Linux Docker - GrapeCity.ActiveReports.Core.Document.Drawing.Gdi

Posted by: chris.straw on 17 July 2023, 6:47 am EST

    • Post Options:
    • Link

    Posted 17 July 2023, 6:47 am EST

    The package GrapeCity.ActiveReports.Core.Document.Drawing.Gdi has a requirement on System.Drawing.Common. This prevents running Section Reports within a Linux Docker Container.

    The dependency on System.Drawing.Common appears to have been added back with version 4.x. With version 3.x, there was no dependency on System.Drawing.Common, but I’m running v17, which requires 4.x

    Here’s the error:

    2023-07-17 15:41:47 System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation.

    2023-07-17 15:41:47 —> System.TypeInitializationException: The type initializer for ‘GrapeCity.ActiveReports.Document.Section.Page’ threw an exception.

    2023-07-17 15:41:47 —> System.TypeInitializationException: The type initializer for ‘GrapeCity.ActiveReports.Core.Document.Drawing.Gdi.GdiTextLayoutService’ threw an exception.

    2023-07-17 15:41:47 —> System.TypeInitializationException: The type initializer for ‘Gdip’ threw an exception.

    2023-07-17 15:41:47 —> System.PlatformNotSupportedException: System.Drawing.Common is not supported on non-Windows platforms. See https://aka.ms/systemdrawingnonwindows for more information.

    2023-07-17 15:41:47 at System.Drawing.LibraryResolver.EnsureRegistered()

    2023-07-17 15:41:47 at System.Drawing.SafeNativeMethods.Gdip.PlatformInitialize()

    2023-07-17 15:41:47 at System.Drawing.SafeNativeMethods.Gdip…cctor()

    2023-07-17 15:41:47 — End of inner exception stack trace —

    2023-07-17 15:41:47 at System.Drawing.SafeNativeMethods.Gdip.GdipCreateBitmapFromScan0(Int32 width, Int32 height, Int32 stride, Int32 format, IntPtr scan0, IntPtr& bitmap)

    2023-07-17 15:41:47 at System.Drawing.Bitmap…ctor(Int32 width, Int32 height, PixelFormat format)

    2023-07-17 15:41:47 at System.Drawing.Bitmap…ctor(Int32 width, Int32 height)

    2023-07-17 15:41:47 at GrapeCity.ActiveReports.Core.Document.Drawing.Gdi.GdiTextLayoutService…cctor()

    2023-07-17 15:41:47 — End of inner exception stack trace —

    2023-07-17 15:41:47 at GrapeCity.ActiveReports.Win.Services.GdiTextLayoutServiceFactory.Create()

    2023-07-17 15:41:47 at GrapeCity.ActiveReports.Document.Section.Page…cctor()

    2023-07-17 15:41:47 — End of inner exception stack trace —

    2023-07-17 15:41:47 at GrapeCity.ActiveReports.Document.Section.Page…ctor()

    2023-07-17 15:41:47 at System.RuntimeType.CreateInstanceOfT()

    2023-07-17 15:41:47 — End of inner exception stack trace —

    2023-07-17 15:41:47 at System.RuntimeType.CreateInstanceOfT()

    2023-07-17 15:41:47 at System.Activator.CreateInstanceT

    2023-07-17 15:41:47 at GrapeCity.ActiveReports.Core.Document.DocumentBase`1.CreatePage()

    2023-07-17 15:41:47 at GrapeCity.ActiveReports.SectionReport.ProcessPage()

    2023-07-17 15:41:47 at GrapeCity.ActiveReports.SectionReport.RunImpl(Boolean syncDocument)

    2023-07-17 15:41:47 at GrapeCity.ActiveReports.SectionReport.Run(Boolean syncDocument)

    2023-07-17 15:41:47 at GrapeCity.ActiveReports.SectionReport.Run()

  • Posted 17 July 2023, 10:49 pm EST - Updated 18 July 2023, 8:37 pm EST

    Hi Chris,

    To run your SectionReport in a Linux environment you’ll need to change its ‘CompatabilityMode’ to ‘CrossPlatform’ as GDI is only supported in the Windows platform.

    You may also install the ‘libgdiplus’ to use packages from ‘System.Drawing’ in the Linux platform.

    You can learn more about the same in the following StackOverflow post: I am using .NET Core with C# on Linux, and library System.Drawing is missing.

    Regards,

    Anand

  • Posted 18 July 2023, 2:29 am EST - Updated 18 July 2023, 2:56 am EST

    This is a .net 7 application running on a Linux Container using Active Reports 17

    The section reports are set to CrossPlatform. The root issue is the nuget package https://www.nuget.org/packages/GrapeCity.ActiveReports.Core.Document.Drawing.Gdi is referencing System.Drawing.Common. The reference was added in the 4.x release.

    The 3.x version of the library does not have this reference.

    https://www.nuget.org/packages/GrapeCity.ActiveReports.Core.Document.Drawing.Gdi/3.6.3#dependencies-body-tab

  • Posted 18 July 2023, 8:38 pm EST - Updated 18 July 2023, 8:44 pm EST

    Hi Chris,

    We tried to replicate the issue by running an ActiveReports 17 - SectionReport application (NET 7) in a Linux Docker Container and got the same error you are getting (see image)

    However, installing ‘libgdiplus’ in our Linux container seems to fix the issue.

    Please make sure you install libgdiplus in your Docker Linux Container.

    Your Dockerfile should look like this:

    FROM mcr.microsoft.com/dotnet/core/aspnet:7.0 AS base
    RUN apt-get update && apt-get install -y libgdiplus
    
    WORKDIR /app
    FROM mcr.microsoft.com/dotnet/core/sdk:7.0 AS build
    [...]
    

    Regards,

    Anand

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels