SkiaSharp exception when converting Excel to PDF

Hello, 

I have been attempting to convert an Excel workbook to a PDF document using XlsIO. I am using the latest version of .NET MAUI on Android 12. Here is the error:


---> System.InvalidOperationException: The version of the native libSkiaSharp library (88.0) is incompatible with this version of SkiaSharp. Supported versions of the native libSkiaSharp library are in the range [80.2, 81.0).

   at SkiaSharp.SkiaSharpVersion.CheckNativeLibraryCompatible(Version minSupported, Version current, Boolean throwIfIncompatible)

   at SkiaSharp.SkiaSharpVersion.CheckNativeLibraryCompatible(Boolean throwIfIncompatible)

   at SkiaSharp.SKObject..cctor()

   --- End of inner exception stack trace ---

   at SkiaSharp.SKPaint..ctor(IntPtr handle, Boolean owns)

   at SkiaSharp.SKPaint..ctor()

   at Syncfusion.Drawing.SkiaSharpHelper.FontExtension..ctor(String fontName, Single fontSize, FontStyle style, GraphicsUnit unit)

   at Syncfusion.XlsIORenderer.ExcelToPdfConverter.GetPdfTrueTypeFont(Font font, Boolean isEmbedFont, Stream alternateFontStream)

   at Syncfusion.XlsIORenderer.ExcelToPdfConverter.GetPdfFont(Font nativeFont, Boolean isEmbedFont, Stream alternateFontStream)

   at Syncfusion.XlsIORenderer.ExcelToPdfConverter.DrawCells(WorksheetImpl sheet, Int32 firstRow, Int32 firstColumn, Int32 lastRow, Int32 lastColumn, PdfGraphics graphics, Single originalWidth, Single startX, Single startY, Single rangeWidth)

   at Syncfusion.XlsIORenderer.ExcelToPdfConverter.DrawRow(IWorksheet wkSheet, Int32 startColIndex, Int32 endColIndex, Int32 startRowIndex, Int32 endRowIndex, Single xValue, Single yValue, Single originalWidth, Single startX, Single startY, Single rangeWidth, Single rangeHeight)

   at Syncfusion.XlsIORenderer.ExcelToPdfConverter.DrawRow(IWorksheet wkSheet, Int32 startColumn, Int32 endColumn, Int32 startRow, Int32 endRow, Single xValue, Single yValue, Single originalWidth, Boolean isBlank)

   at Syncfusion.XlsIORenderer.ExcelToPdfConverter.DrawSheet(IWorksheet wkSheet, IRange[] printAreas)

   at Syncfusion.XlsIORenderer.ExcelToPdfConverter.DrawWorkSheet(IWorksheet worksheet, Int32 sheetsCount, LayoutOptions layoutOptions)

   at Syncfusion.XlsIORenderer.ExcelToPdfConverter.ConvertDocument()

   at Syncfusion.XlsIORenderer.ExcelToPdfConverter.Convert()

   at Syncfusion.XlsIORenderer.XlsIORenderer.ConvertToPDF(IWorkbook workbook)



How can I go about fixing this?


5 Replies 1 reply marked as answer

RS Ramya Sivakumar Syncfusion Team March 3, 2022 01:35 PM UTC

Hi Michael, 

Greetings from Syncfusion. 

We suspect that the issue occurs due to a specific configuration in your MAUI app. So kindly share the issue reproducing sample, which will be helpful for us in investigating the query and finding the exact root cause for the issue. 

Regards, 
Ramya. 



MI Michael replied to Ramya Sivakumar March 3, 2022 09:24 PM UTC

A link to the repository for the app is https://github.com/mvan4310/NSSInvoiceApp


The problem is in the DataService class, inside the ConvertInvoiceToPDF function at line 280. The two lines are commented out at the moment until I could find a fix.



RS Ramya Sivakumar Syncfusion Team March 4, 2022 09:32 AM UTC

Hi Michael,

Thanks for sharing the details.

We have validated the exception issue and found that the exception is thrown due to an incorrect NuGet package. You are using the Xamarin NuGet instead of the .NET NuGet package, So the exception occurs. We request you to use Syncfusion.XlsIORenderer.NET to resolve the issue.

Please refer to the following link to know more about the required NuGet packages.  
  
Kindly try this and let us know whether it helps.

Regards,
Ramya.
 


Marked as answer

MI Michael replied to Ramya Sivakumar March 4, 2022 07:26 PM UTC

I have updated the Nuget references from Xamarin to .Net versions, and am now experiencing a different but related error:


System.TypeInitializationException

Message=The type initializer for 'SkiaSharp.SKObject' threw an exception.


I have pushed the changes for the nugets and uncommented lines for the XlsIORenderer. I apologize if I am overlooking something.


Edit to Add: I am able to create and modify Excel documents. It seems to be the conversion to PDF that is the only issue.


Final edit: This was solved. It took me removing the packages again, adding them back in, and cleaning the project before rebuilding. I appreciate all the help



RS Ramya Sivakumar Syncfusion Team March 7, 2022 05:25 AM UTC

Hi Michael, 

We are glad that the provided suggestion helped you. Please let us know if you need any further assistance. 

Regards, 
Ramya. 



Loader.
Up arrow icon