QuestPDF / QuestPDF

QuestPDF is a modern open-source .NET library for PDF document generation. Offering comprehensive layout engine powered by concise and discoverable C# Fluent API. Easily generate PDF reports, invoices, exports, etc.
https://www.questpdf.com
Other
12k stars 629 forks source link

Net6 WPF issue with SkiaSharp.NativeAssets.Win32 and HarfBuzzSharp.NativeAssets.Win32 #694

Closed lukbud14 closed 1 year ago

lukbud14 commented 1 year ago

Hello,

First of all, I would like to thank you for this excellent NuGet package! It seems that PDF reports will no longer be a pain in the neck.

I tried creating a few test reports in a pure console application, and everything worked perfectly. There wasn't a single issue. Thanks to the experience gained from this testing, I decided to try implementing this library into an already completed .NET 6 WPF application, and I immediately encountered an issue at the very beginning. When creating a report, I am encountering the following exceptions.

I tried to find the missing DLL on nuget.org, installed packages, but it didn't help me in any way.

Has anyone addressed this here before? From what I've found in other issues, they were not related to WPF and Windows development. If I have created a duplicate topic unnecessarily, I apologize.

Dependencies - Packages image

Something from csproj

<PropertyGroup>
        <TargetFramework>net6.0-windows</TargetFramework>
        <Nullable>enable</Nullable>
        <OutputPath>..\..\..\bin\$(Configuration)</OutputPath>
        <UseWPF>true</UseWPF>
        <ImportWindowsDesktopTargets>true</ImportWindowsDesktopTargets>
        <IncludePackageReferencesDuringMarkupCompilation>true</IncludePackageReferencesDuringMarkupCompilation>
        <CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
        <Configurations>Debug;Release</Configurations>
        <Platforms>AnyCPU;x86</Platforms>
</PropertyGroup>
<PackageReference Include="QuestPDF" Version="2023.10.1" />
<PackageReference Include="System.Runtime.Extensions" Version="4.3.1" />

Exceptions

System.TypeInitializationException: 'The type initializer for 'QuestPDF.Fluent.Document' threw an exception.'

InitializationException: The QuestPDF library has encountered an issue while loading one of its dependencies. This type of error often occurs when the current runtime is missing necessary NuGet packages. 

Please ensure the following NuGet packages are added to your project and has matching versions:
 - SkiaSharp.NativeAssets.Win32
 - HarfBuzzSharp.NativeAssets.Win32
For a detailed understanding, please examine the inner exception and consult the official SkiaSharp library documentation
System.TypeInitializationException: 'The type initializer for 'QuestPDF.Fluent.Document' threw an exception.'
TypeInitializationException: The type initializer for 'SkiaSharp.SKTypeface' threw an exception.
System.TypeInitializationException: 'The type initializer for 'QuestPDF.Fluent.Document' threw an exception.'
DllNotFoundException: Unable to load DLL 'libSkiaSharp' or one of its dependencies: The specified module could not be found. (0x8007007E)

Here are some of the selected DLLs that are published during the application build. image

MarcinZiabek commented 1 year ago

Hi 😀 Thank you for reaching out and for your kind words.

It seems that SkiaSharp dependencies are more and more problematic recently.

These two nugets should already by added implicitly (as transitive packages), but let's make sure they are properly added as explicit dependencies to your primary/compiled project:

image
lukbud14 commented 1 year ago

Hello,

I apologize for my previous incorrect response. The files you mentioned in the runtime\native folder are there. I have deleted my previous incorrect answer :).

However, I have found a solution. Initially, I had the QuestPDF reference only in the project library MyApp.Reports. Once I added the QuestPDF reference to the startup project MyApp as well, everything works.

MarcinZiabek commented 1 year ago

@lukbud14 This is actually a crucial observation.

Do you have any suggestions on improving the exception message to emphasize that both listed nugets should be installed in the primary/main/startup project?