Hello! I am trying to use groupdocs.Parser in .NET to parse some images from a word document. When I run this on Windows 10 there is no issue and everything works smoothly.
However when running this on Linux I am getting an exception because there is an internal dependency to System.Drawing which is no longer supported for linux. I have installed all other packages and dependencies that are mentioned in the installation page but this problem seems to persist. Is there a workaround that does not involve System.Drawing since it no longer supports Linux?
@maritinaTsanta
Please share following details and we’ll look into this scenario:
- OS version
- API version that you are evaluating (e.g. 19.10, 21.1)
- Complete stack trace of this issue
@Atir_Tahir
Thank you for the quick reply!
The API version I am using is 22.2.0
My service is running on Ubuntu server 20.04 LTS.
The stack trace for this issue is:
Exception #0
Type : System.TypeInitializationException, System.Private.CoreLib
Message : The type initializer for ‘Gdip’ threw an exception.
StackTrace :
at System.Drawing.SafeNativeMethods.Gdip.GdipCreateMatrix2(Single m11, Single m12, Single m21, Single m22, Single dx, Single dy, IntPtr& matrix)
at Aspose.Pdf.ImagePlacementAbsorber.#=zLvshk2o=(Page #=z33S4xiY=, OperatorCollection #=zom8hpA4=, Resources #=zYv0iFbY=)
at Aspose.Pdf.ImagePlacementAbsorber.Visit(Page page)
at .(Int32 , PageAreaOptions )
at .(Nullable1 , PageAreaOptions ) at .(Nullable
1 , PageAreaOptions )
at GroupDocs.Parser.Parser.GetImages()
at Yodiwo.FEMP.Libraries.ReportingManagement.Render.GetGraphFromReport(Byte[] doc, ILogger logger) in C:\DEV\yodifem\uServicesScoped\Libraries\Yodiwo.FEMP.Libraries.ReportingManagement\Render.cs:line 130
Exception #0.0
Type : System.PlatformNotSupportedException, System.Private.CoreLib
Message : 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.
StackTrace :
at System.Drawing.LibraryResolver.EnsureRegistered()
at System.Drawing.SafeNativeMethods.Gdip.PlatformInitialize()
at System.Drawing.SafeNativeMethods.Gdip…cctor()
@maritinaTsanta
We are investigating this scenario. Your investigation ticket ID is PARSERNET-1881. We’ll let you know if any further details are required.
@maritinaTsanta
Could you please share following details:
- Code snippet using that issue could be reprdouced
- The version of System.Drawing.Common which is used in the project
This is the code that produces the error, the input doc for this function is a byte array of a pdf document. I do not use System.Drawing.Common anywhere in my project, its appearance in the exception is, from my understanding, due to the groupdocs.Parser reference to that package:
image.png (16.3 KB)
private static byte[] GetGraphFromReport(byte[] doc, ILogger logger)
{
try
{
Stream stream = new MemoryStream(doc);
using (Parser parser = new Parser(stream))
{
// Extract images
IEnumerable<PageImageArea> images = parser.GetImages();
// Check if image extraction is supported
if (images == null)
{
logger.LogError(null, "Images extraction isn't supported");
}
// Iterate over images
byte[] res = null;
foreach (PageImageArea image in images)
{
// Save each image
using (MemoryStream ms = new MemoryStream())
{
image.GetImageStream().CopyTo(ms);
res = ms.ToArray();
}
}
return res;
}
}
catch (Exception ex)
{
logger.LogError(ex, "Error when trying extract images");
DebugEx.TraceErrorException(ex);
return null;
}
}
@maritinaTsanta
We are further investigating this scenario. You’ll be notified in case of any progress update.
@maritinaTsanta
We have a workaround for the issue with System.Drawing.Common
.
Create runtimeconfig.template.json
file at the project root folder with the following content:
{
"configProperties": {
"System.Drawing.EnableUnixSupport": true
}
}