Fixed DevExpress.XtraPrinting Throw PlatformNotSupportedException

My ASP.NET6 WebAPI containers crashed. after add reference DevExpress.XtraPrinting.PrintingSystemBase and Full Exception here

System.TypeInitializationException: The type initializer for 'DevExpress.XtraPrinting.PrintingSystemBase' threw an exception.
 ---> System.PlatformNotSupportedException: System.Drawing.Common is not supported on non-Windows platforms. See https://docs.devexpress.com/XtraReports/403589/ for more information.
   at DevExpress.XtraPrinting.PrintingSystemBase.AssertPlatformSupported()
   at DevExpress.XtraPrinting.PrintingSystemBase..cctor()
   --- End of inner exception stack trace ---
   at DevExpress.XtraPrinting.PrintingSystemBase.set_EngineKind(EngineKind value)
   at DevExpress.Printing.CrossPlatform.CustomEngineHelper.set_CustomEngineType(Type value)
   at DevExpress.Printing.CrossPlatform.CustomEngineHelper.RegisterCustomDrawingEngine(Type engineType)
   at ds.Invest.WebAPI.Helper.ServiceRegistor.AddReporting(IServiceCollection pServices) in /var/jenkins_home/workspace/INVEST_SERVICE/Web/ds.Invest.WebAPI/Helper/ServiceRegistor.cs:line 31
   at ds.Invest.WebAPI.Startup.ConfigureServices(IServiceCollection services, IWebHostEnvironment env, IConfiguration config) in /var/jenkins_home/workspace/BNZ INVEST_SERVICE/Web/ds.Invest.WebAPI/Startup.cs:line 123
   at ds.Invest.WebAPI.MainWeb.Main(String[] args) in /var/jenkins_home/workspace/BNZ INVEST_SERVICE/Web/ds.Invest.WebAPI/MainWeb.cs:line 45

Root Cause

Solution

  • Workaround Solution: In webapi project file, add this section
<ItemGroup>
    <RuntimeHostConfigurationOption Include="System.Drawing.EnableUnixSupport" Value="true" />
</ItemGroup>

Reference


Discover more from naiwaen@DebuggingSoft

Subscribe to get the latest posts sent to your email.