Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MuPDFCore.dll in MuPDFCore NuGet package 1.7 has no strong name #23

Closed
wickyhu opened this issue Mar 28, 2023 · 3 comments
Closed

MuPDFCore.dll in MuPDFCore NuGet package 1.7 has no strong name #23

wickyhu opened this issue Mar 28, 2023 · 3 comments

Comments

@wickyhu
Copy link

wickyhu commented Mar 28, 2023

Hi,

I just added MuPDFCore 1.7 NuGet package to my project, but MuPDFCore.dll couldn't be loaded because of no strong name:

MuPDFCore, Version=1.7.0.0, Culture=neutral, PublicKeyToken=null

Is this an issue or was designed?
Should I need to build from source to add strong name?

Thanks!
Wicky Hu

@arklumpus
Copy link
Owner

arklumpus commented Mar 29, 2023

Hi! Thanks for pointing this out, I didn't realise strong naming was still around (I have been using mostly .NET Core/.NET, and strong naming doesn't really matter anymore). Assuming it won't break anything, I will try to strong name-sign the next release!

In the meantime, assuming you don't want to disable strong naming in your project, you don't need to build from source; you can use the following workaround:

  1. Uninstall the MuPDFCore NuGet package from your project.

  2. Download the MuPDFCore nupkg file, rename it to have a .zip extension and extract it somewhere.

  3. Now, you need to sign the DLL to give it a strong name. I assume you have a .snk file that you have been using to sign your project:

    • Open the Developer Command Prompt that is installed with Visual Studio and double-check that you have the ilasm, ildasm and sn tools.

    • Use cd to change directory to the extracted nupkg file.

    • Execute:

      sn -vf lib\netstandard2.0\MuPDFCore.dll
      

      This should show a message saying lib\netstandard2.0\MuPDFCore.dll does not represent a strongly named assembly - just to confirm what we're working with.

    • Run:

      ildasm /all /out=lib\netstandard2.0\MuPDFCore.il lib\netstandard2.0\MuPDFCore.dll
      

      This will disassemble the MuPDFCore DLL and produce a file called MuPDFCore.il (containing the disassembled code) and another file called MuPDFCore.res (containing the resources) in the lib\netstandard2.0 folder.

    • Unfortunately, the ilasm tool has a bug when dealing with NaNs, so we need to make a small change in the IL file. Open the MuPDFCore.il file in a text editor, and replace every occurrence of ldc.r8 -nan(ind) with ldc.r8 (00 00 00 00 00 00 F8 FF). There should be 10 occurrences. Save and close.

    • You can now rebuild the DLL signing it with the strong name key with this command:

      ilasm /dll /key=path\to\key.snk /resource=lib\netstandard2.0\MuPDFCore.res lib\netstandard2.0\MuPDFCore.il
      

    This will overwrite the lib\netstandard2.0\MuPDFCore.dll library with the signed one.

    • If you now execute:
      sn -vf lib\netstandard2.0\MuPDFCore.dll
      
      This should show a message saying Assembly 'lib\netstandard2.0\MuPDFCore.dll' is valid, confirming that everything has worked.
  4. You can finally add the reference back into the project. In Visual Studio, add a reference to the signed MuPDFCore.dll.

  5. Finally, right click on the project in the Solution Explorer and select Add > Existing item.... Locate and select the MuPDFWrapper.dll file for your architecture (if you're building for Any CPU or x86, select the MuPDFWrapper.dll file in the runtimes\win-x86\native folder within the extracted NuGet package, if you're building for x64 select instead the one in runtimes\win-x64\native). After adding the item to the project, set the Copy to Output Directory action to Copy if newer in the file properties.

You should now be able to debug and execute your program.

I hope this makes sense, let me know if something isn't clear or if you have any further questions!

@wickyhu
Copy link
Author

wickyhu commented Mar 29, 2023

Hi,

Thank you very much for the information.
Issue resolved.

Best Regards
Wicky

@arklumpus
Copy link
Owner

Hi, starting from the new version 1.8.0, the library is now strong-name signed.

I'm closing this issue, let me know if you have any more problems!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants