Spire.PDF is a professional PDF library applied to creating, writing, editing, handling and reading PDF files without any external dependencies. Get free and professional technical support for Spire.PDF for .NET, Java, Android, C++, Python.

Fri Jan 24, 2020 10:51 am

Hi,

We have an issue where we have a library that we've had to create in .NET Standard 2.0, but our unit tests run in .NET 4.7.1

Although the two frameworks are compatible, SpirePdf.Net throws an error due to a semantic versioning error between the two versions of the DLL in the NuGet Package.

I can confirm the problem exists in FreeSpire.Pdf versions 5.10.0 and 5.4.0

Your DLLs in the lib folder are actually showing different versions, which confuses .NET and requires Version Redirects to be used in the projects:

  • net20 - 5.10.5.20020
  • net40 - 5.10.5.20040
  • net46 - 5.10.5.20046
  • netcoreapp2.0 - 5.10.5.20420
  • netstandard2.0 - 5.10.5.20320


As per Microsoft's documentation, you should try to keep the Assembly Version the same, but the Assembly File Version can differ so that you can tell your DLLs apart.

This would mean that all your DLLs would have an AssemblyVersion of 5.10.5.0 but your AssemblyFileVersion could be set to contain the last digits as above.

Doing this will save any others multi-targetting a massive headache!

Thanks!

Stuart

KaraokeStu
 
Posts: 2
Joined: Fri Jan 24, 2020 9:43 am

Mon Jan 27, 2020 3:34 am

Hello Stuart,

Thanks for your inquiry and sorry for my late reply as weekend.
I simulated your case and found the application would throw the exception "Could not load file or assembly 'Spire.Pdf, Version = 5.10.5.20320, Culture = neutral, PublicKeyToken = 663f351905198cb3' or one of its dependencies." when installing FreeSpire.PDF 5.10.0 via Nuget. Did you get the same exception?
After investigation we found this is related to the internal mechanisms of VS and Nuget. You can find that the dlls of .net standard weren’t copied in bin/Debug folder when running the .NET Framework 4.7 application. Thus, it could not load file or assembly Spire.PDF Version=5.10.5.20320 of netStandard 2.0. Sorry at present there is no better way to get rid of this issue.
As a workaround, you can download Free Spire.PDF for .NET Version:5.10 from our website, manually reference the dlls of netStandard 2.0 folder and then install the following dependency libraries to test your case. If there is any other question, just feel free to contact us.
1) .NETStandard 2.0
SkiaSharp (>= 1.68.0)
System.Buffers (>= 4.5.0)
System.Memory (>= 4.5.0)
System.Runtime.CompilerServices.Unsafe (>= 4.5.0)
System.Text.Encoding.CodePages (>= 4.5.0)
2).NETFramework 4.7
SkiaSharp (>= 1.68.0)

Sincerely,
Rachel
E-iceblue support team
User avatar

rachel.lei
 
Posts: 1571
Joined: Tue Jul 09, 2019 2:22 am

Mon Jan 27, 2020 10:04 am

Hi Rachel,

Thanks for getting back to me so quickly.
Yes, that was the error I received.

As I stated the issue is actually down to the patch number included at the end of your assembly versions, however the following workaround also works without having to copy DLLs (as the DLLs get copied as part of my referenced project)

The workaround is to create an app.config within your .NET 4.7.x project and add the following:

Code: Select all
<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="Spire.Pdf" publicKeyToken="663f351905198cb3" culture="neutral" />
        <bindingRedirect oldVersion="5.10.5.20046-5.10.5.20320" newVersion="5.10.5.20046" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
</configuration>

KaraokeStu
 
Posts: 2
Joined: Fri Jan 24, 2020 9:43 am

Tue Jan 28, 2020 2:52 am

Hi Stuart,

Thanks for your feedback.
Sorry, I tested your workaround but it didn't work on my side. I will do further investigation on this issue. Besides, now we are on Chinese New Year holiday (24/1/2020-/2/2/2020), I will discuss with our Dev team when we get back to the office on 3/2/2020 and then give you a feedback.

Sincerely,
Rachel
E-iceblue support team
User avatar

rachel.lei
 
Posts: 1571
Joined: Tue Jul 09, 2019 2:22 am

Mon Feb 03, 2020 9:51 am

Hi Stuart,

Thanks for your patient waiting.
We did more tests but sorry your workaround still didn't work on my side. To help us further investigate it and to optimize it, could you please provide the following information? Thanks in advance.
1. Your testing project, you could send it to us via email ([email protected]).
2. Your testing environmet, such as OS information (E.g. Windows 7, 64bit) and Region setting (E.g. China, Chinese).
3. Your Visual Studio version.

Sincerely,
Rachel
E-iceblue support team
User avatar

rachel.lei
 
Posts: 1571
Joined: Tue Jul 09, 2019 2:22 am

Return to Spire.PDF