Aspose.Pdf .Net thows error because of System.Drawing.Common dependency in dotnet 6.0 when using linux

Please look at my sample project here. I have dockerfile in the project as well.
I have installed libgdiplus and installed nuget package SkiaSharp.NativeAssets.Linux.NoDependencies

I am trying to remove black pages from pdf using aspose pdf.

This line https://github.com/sunilshahi/AsposePdfNet6/blob/master/AsposePdfNet6/Pages/Privacy.cshtml.cs#L55
and
https://github.com/sunilshahi/AsposePdfNet6/blob/master/AsposePdfNet6/Pages/Privacy.cshtml.cs#L32

throws exception.

This is only happening in linux not on windows.

-------EXCEPTION--------

The type initializer for ‘Gdip’ threw an exception.

at System.Drawing.SafeNativeMethods.Gdip.GdipCreateMatrix2(Single m11, Single m12, Single m21, Single m22, Single dx, Single dy, IntPtr& matrix)
at #=zc37PDvqhjJhFJ7Th$yP201U$ylaf74hg2w==.#=zvqZkU0g=(Single #=zsVIZ3L4=, Single #=zF9KnC$Q=, Single #=z28gG5ds=, Single #=zEr3XCA4=, Single #=zpRv0CwI=, Single #=zhcritWg=, #=zV71mTzZAOL89qaDq0fysgUMUk5rsWUFSSg== #=z1Er4bdQ=)
at #=z8ji8PcCb1ywUbV4y6UiEKs9xkoNoXfSJQWMKzN_TYhwI.#=zAUwQXE5efflE(#=z1nNf2afKdyI9MKLxx_oOlwlFofIwSimeyg== #=zVj3TBps=, #=za8ZRH_0Yk2d99N6q91dzRSae9vaQEnNnIFYqn1c= #=z6Nli1WEjRgpZ, #=zkQi4kBA04vuavCks9LRrOL9JMruGnvdvOQ== #=zPlHPmMg=, Single #=zctvlxpXr1JIL, Single #=zovwo0Rw_96ma, Boolean #=zC6NrB7mbgPpekgxkBg==, Int32 #=zC9yKE0l5YpUdA5uH_xtuG0I=, Boolean #=zu0fpoc6yN1UL, Double& #=zxx6_4PU=, Double& #=zDyW2pao=, #=zIRn9vQD5BlbDNj46oHuAkXqu6SeIzfa9ZQ==& #=zp85Nw$4=)
at #=z8ji8PcCb1ywUbV4y6UiEKs9xkoNoXfSJQWMKzN_TYhwI…ctor(#=z$GtRQPT4_T3dmyQTgv1g6IQsW2Ff #=zRl0TbqM=, #=z1nNf2afKdyI9MKLxx_oOlwlFofIwSimeyg== #=zVj3TBps=, #=za8ZRH_0Yk2d99N6q91dzRSae9vaQEnNnIFYqn1c= #=z6Nli1WEjRgpZ)
at #=zYkBljhijl77Uqw19zwhMulrfZyQY_F9QNFxvR9E=.#=zLwInxTqVw$UL(#=z$GtRQPT4_T3dmyQTgv1g6IQsW2Ff #=zRl0TbqM=, #=z1nNf2afKdyI9MKLxx_oOlwlFofIwSimeyg== #=zVj3TBps=, #=za8ZRH_0Yk2d99N6q91dzRSae9vaQEnNnIFYqn1c= #=z6Nli1WEjRgpZ)
at Aspose.Pdf.Page.IsBlank(Double fillThresholdFactor)
at AsposePdfNet6.Pages.PrivacyModel.OnGet() in C:\Users\Sunil\source\repos\AsposePdfNet6\AsposePdfNet6\Pages\Privacy.cshtml.cs:line 32
at lambda_method27(Closure , Object , Object[] )
at Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure.ExecutorFactory.ActionResultHandlerMethod.Execute(Object receiver, Object[] arguments)
at Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure.PageActionInvoker.InvokeHandlerMethodAsync()

-----INNER EXCEPTION----
System.Drawing.Common is not supported on non-Windows platforms. See Breaking change: System.Drawing.Common only supported on Windows - .NET | Microsoft Learn for more information.

at System.Drawing.LibraryResolver.EnsureRegistered()
at System.Drawing.SafeNativeMethods.Gdip…cctor()

@pratyushrai

We already logged an issue to test Aspose.PDF functionality under .NET 6.0 in non-Windows environments as PDFNET-50918. You will be notified via this forum thread once this issue is resolved.

We apologize for your inconvenience.

Thanks for the response @tahir.manzoor

Is there a official versions compatibility chart vs different OS for aspose pdf and aspose words. We were planning to migrate to dotnet 6 and start using linux seems like this is the only blocker. We updated our license just for this only to realize this is not supported in linux. Any pointers to what our options are at this point would be helpful.

Thanks

@pratyushrai

Unfortunately, there is no compatibility chart vs different operating systems. However, you can find your required detail in following articles of Aspose.PDF and Aspose.Words.

Seems like this task PDFNET-50918 has been floating around for almost a year. I see oldest mention of the task here:

Its from November 2021. Its been almost a year and this task seems to still be not worked on. What is the status and priority of this task? Do we have any idea when this will be addressed?

I am afraid we do not have luxury to wait on this any longer.

@asad.ali mentioned this task was top priority back in May 19th. Here .NET 6 Support missing for Aspose.Cells, Aspose.Imaging, Aspose.PDF, Aspose.Slides.NET on macOS, Linux

Can we get an update on what we should expect? Should we start looking into another library?

@pratyushrai

We have logged your concerns in our issue tracking system. We will inform you once there is an update available on it. We apologize for your inconvenience.

Here we are its Nov 8th 2022. Microsoft will release dotnet 7 later today and PDFNET-50918 is one year old at this point. And there is no clear communication on what is going on with this task.

How long should we wait? mind you we bought new license just so that we could upgrade to dotnet 6.
Please give us more details than this issue is being logged.

@pratyushrai

The release of Aspose.PDF beta version is scheduled and will be available by the end of November 2022. Please note that this ETA is not final at the moment. We will be sure to inform you once there is any news available on it.

Hey @tahir.manzoor I see that a new version 22.11.0 was released today NuGet Gallery | Aspose.PDF 22.11.0 is this the beta version you mentioned?

@pratyushrai

Yes, 22.11 is the beta version and we are further improving this feature and doing more and more tests. You can also use it and share your feedback in case you notice any issues.

Unfortunately the Aspose.PDF@22.11.0 version does not solve the problem on dotnet7. Still getting System.PlatformNotSupportedException: System.Drawing.Common is not supported on non-Windows platforms.

@manuelnaujoks

Your concerns have been recorded along with the ticket and we will soon update you once the ticket is resolved. We apologize for the inconvenience.

Aspose.PDF@22.12.0 does not solve the problem either on both dotnet6 or dotnet7. Still getting same error.

@pratyushrai
@manuelnaujoks

Aspose.PDF.Drawing NuGet package was released, DLL in this package doesn’t have System.Drawing.Common dependency.

Is there any documentation how this is to be used?

Just include the Aspose.PDF and the Aspose.PDF.Drawing nuget packages in a linux container and it will work?

Just adding Aspose.PDF.Drawing does not change the behaviour: I’m using PngDevice to export single pages of a PDF which throws on Linux the following Exception with StackTrace:

System.PlatformNotSupportedException: System.Drawing.Common is not supported on this platform.
anzen_server | at System.Drawing.Drawing2D.Matrix…ctor(Single m11, Single m12, Single m21, Single m22, Single dx, Single dy)
anzen_server | at #=zDWlnVl2WPEQwJBXlUBwpuUMMsmVSeoH8VObjgQE=…ctor(Single #=zUJkdsSk=, Single #=zEcuw8Q4=, Single #=z1mn9UaM=, Single #=zsPqFcjs=, Single #=zgSmxrcY=, Single #=zm1r5nH8=)
anzen_server | at #=zYqjI0WKt2Qp40Rpv3cy7AbpOBfvlpVdRJg==.#=zMjy1U3A=(Single #=zUJkdsSk=, Single #=zEcuw8Q4=, Single #=z1mn9UaM=, Single #=zsPqFcjs=, Single #=zgSmxrcY=, Single #=zm1r5nH8=, #=zHOfBzK1HOFplxnI0MlcFE2kKnWBiifufdQ== #=zQekjhis=)
anzen_server | at #=z9GE0hk2XfKEBxoawmuqrg_$eDlQ$Cy91M7JkyWqZzS1B.#=zkq956zqXa_zN(#=zNmsVZT4wg6kbjrIToJVnYrp6GctPBPxfZg== #=zRSpRhUg=, #=zF$6I2bE1TIl$ND4xalvyFjI_ofDK3LVAUKlwkBg= #=zZZnXcuVqD9sR, #=zHwkwyllG3$GKY0lmovMiUvXgDK2n8ypErg== #=zInrZ4CY=, Single #=zRrbAKb1Kc3d5, Single #=znL$wNve364Bo, Boolean #=zLYYuuNikxpHjf8hDXw==, Int32 #=zTWB2P8u6csXdiE610sZf6z8=, Boolean #=z2dzjH7bMf47v, Double& #=zc2J8auE=, Double& #=zJoyUHl0=, #=zr0R7PzVcylW0RaZsz2wLvBZRUBH7ONfBuA==& #=zkeFcED8=)
anzen_server | at #=z9GE0hk2XfKEBxoawmuqrg_$eDlQ$Cy91M7JkyWqZzS1B…ctor(#=zxrfzKlOyQs3X$uIDnMU_JYajVGDh #=zQ9ilHsc=, #=zNmsVZT4wg6kbjrIToJVnYrp6GctPBPxfZg== #=zRSpRhUg=, #=zF$6I2bE1TIl$ND4xalvyFjI_ofDK3LVAUKlwkBg= #=zZZnXcuVqD9sR)
anzen_server | at #=zjroLc8wES_h1ilPWuP2WJb4VKmlo2M1kB_9Ae9Q=.#=zX_xfb2ZEB$rU(#=zxrfzKlOyQs3X$uIDnMU_JYajVGDh #=zQ9ilHsc=, #=zNmsVZT4wg6kbjrIToJVnYrp6GctPBPxfZg== #=zRSpRhUg=, #=zF$6I2bE1TIl$ND4xalvyFjI_ofDK3LVAUKlwkBg= #=zZZnXcuVqD9sR)
anzen_server | at #=zz4hI9qsKj8lF31zAWNdPxM4flu5tikE6d4SVb9O9s5pb.#=zN_aFKSk=(#=zxrfzKlOyQs3X$uIDnMU_JYajVGDh #=zQ9ilHsc=, #=zNmsVZT4wg6kbjrIToJVnYrp6GctPBPxfZg== #=zRSpRhUg=, #=zF$6I2bE1TIl$ND4xalvyFjI_ofDK3LVAUKlwkBg= #=zJ8tC_$M=, #=z9GE0hk2XfKEBxoawmuqrg_$eDlQ$Cy91M7JkyWqZzS1B& #=zq1hVW5Q=)
anzen_server | at #=zsFKlG8DzmhcFb6UsCskPgaqT$TOD.#=zbU5p_EA=(#=z9GE0hk2XfKEBxoawmuqrg_$eDlQ$Cy91M7JkyWqZzS1B& #=zq1hVW5Q=)
anzen_server | at #=zsFKlG8DzmhcFb6UsCskPgaqT$TOD.#=zbU5p_EA=()
anzen_server | at Aspose.Pdf.Devices.ImageDevice.#=zbU5p_EA=(Page #=zRSpRhUg=)
anzen_server | at Aspose.Pdf.Devices.PngDevice.Process(Page page, Stream output)

@HauptlorenzAG

You only need to install Aspose.PDF.Drawing instead of Aspose.PDF. Aspsoe.PDF with Drawing contains Aspose.Drawing inside, installing neither System.Drawing nor Aspose.Drawing is required.

This assembly correctly works under Linux environment. It will be published as separated assembly until we sure that this works absolutely perfect and may replace current System.Drawing-based assembly by 100%. When we ensure that, we will replace System.Drawing version with Aspose.Drawing one.

1 Like

I removed Aspose.PDF: seems to work!
I get now an exception in Aspose.Imaging but I will open an Issue there.

anzen_server | IndexWorker: Unexpected exception while indexing Document with Id ‘199411ca-46b1-4371-a504-6e7daee299bc’: System.PlatformNotSupportedException: System.Drawing.Common is not supported on this platform.
anzen_server | at System.Drawing.SystemFonts.get_DefaultFont()
anzen_server | at Aspose.Imaging.ImageOptionsBase…ctor()
anzen_server | at Aspose.Imaging.ImageOptions.PngOptions…ctor()
anzen_server | at Aspose.Imaging.FileFormats.Png.PngImage.SaveData(Stream stream)
anzen_server | at Aspose.Imaging.DataStreamSupporter.Save(Stream stream)
anzen_server | at appGenerics.Anzen.Infrastructure.Converters.AsposeHelper.ImageToGrayscale(Stream input) in /src/anzen_server/Infrastructure/Converters/AsposeHelper.cs:line 31

@HauptlorenzAG

Thanks for the feedback. Please keep using our API and feel free to create a new topic in case you need further assistance.