0

I have a program using Pdfium and PdfiumViewer. Everything works, but I have to have the pdfium.dll and PdfiumViewer.dll in the same directory as my .exe in order for it to work. If the pdfium.dll is missing, I get "Unable to load DLL 'pdfium.dll'". If PdfiumViewer.dll is missing, I get TypeInitializationException.

I have Costura.Fody as part of my program and I assumed it would've wrapped these dlls into the .exe. Is there any reason why it's not doing that (or a way that I can do it otherwise?)

derekantrican
  • 1,891
  • 3
  • 27
  • 57
  • Maybe you just need to mark this reference as Copy Always: https://code.msdn.microsoft.com/windowsdesktop/Working-with-Copy-to-11fbc251 – Fals Mar 01 '18 at 15:37
  • @Fals those are file properties. I don't have the file in my solution - just the nuget package – derekantrican Mar 01 '18 at 15:41
  • 2
    Pdfium loads a native DLL. This native DLL is not referenced by your program/project. It is just loaded explicitly. Since there is no reference to be resolved towards this native DLL, it is not automatically aware of whether to embed/unpack such a DLL to/from a resource. You have to help FC with regard to native DLLs. Read here what to do: https://github.com/Fody/Costura#native-libraries-and-preloadorder –  Mar 01 '18 at 15:42
  • 1
    @elgonzo Thank you! That's exactly the answer! – derekantrican Mar 01 '18 at 15:51
  • @derekantrican This has been a while ago but I now run into the same problem. Would you like to tell me how you did it? I've already tried everything with costura32 / 64 and embedded resources but no success. thanks in advance – Marcel May 27 '20 at 06:59
  • 2
    @Marcel check out the changes I made here: https://github.com/derekantrican/Ballerina-PDF/commit/6447cba360676d4e499f4030e40eb12ebf84f4d2 – derekantrican May 27 '20 at 17:57

1 Answers1

0

add an existing element lib.dll to the solution and specify the embedded resource type

using (var stream = typeof(Program).Assembly.GetManifestResourceStream("AppName.lib.dll"))
    {
    byte[] assemblyData = new byte[stream.Length];
    stream.Read(assemblyData, 0, assemblyData.Length);
    File.WriteAllBytes("lib.dll", assemblyData);
    }
Mebel Sv
  • 1
  • 1