logo
Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

Options
Go to last post Go to first unread
sau002  
#1 Posted : Friday, August 30, 2019 11:45:49 AM(UTC)
sau002

Rank: Newbie

Groups: Registered
Joined: 8/17/2019(UTC)
Posts: 6
United Kingdom

Hi All,
I am evaluating Pdfium.Net.SDK for my customer. My solution is as follows:


Solution structure
1).NET 20 Standard Class library project (AnyCpu)
2).NET Framework 4.6.1 MS Test project (64 bit)
3).NET Console EXE 4.6.1 (64 bit)

The class library project has a Nuget reference to the latest Pdfium.Net.Sdk
The unit test project has a simple project reference to the Class library
When I try to execute a very simple unit test which invokes a class in the Class library, which in turn invokes Pdfium.Net.Sdk I encounter assembly loading failures.


The Console EXE works perfectly with .NET Standard 20 class library. The unit test not being able to load the assembly is becoming a major blocker.


Any suggestions?

Workaround

If we change the class library project to target .NET Framework 461 instead of .NET Standard 20 then there is no problem. However, this adds on a new challenge. Our environment has a mix of .NET Framework and .NET Core and having a single .NET 20 library would be ideal.


Class library code

Quote:
public class Class2
{
PdfDocument _doc;
public Class2(byte[] contents)
{
_doc = PdfDocument.Load(contents);
}

}


Unit test code

Quote:
[TestMethod]
public void TestMethod1()
{
string file = @"C:\CS15.page6.pdf";
try
{
byte[] contents = System.IO.File.ReadAllBytes(file);
var c = new ClassLibrary1.Class2(contents);
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}

}



Exception

System.IO.FileLoadException
HResult=0x80131040
Message=Could not load file or assembly 'Patagames.Pdf, Version=4.4.6.2020, Culture=neutral, PublicKeyToken=60fd6cf9b15941cf' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
Source=SampleLib.Pdfium.NetSDK


Fusion log
=== Pre-bind state information ===
LOG: DisplayName = Patagames.Pdf, Version=4.4.6.2020, Culture=neutral, PublicKeyToken=60fd6cf9b15941cf
(Fully-specified)
LOG: Appbase = file:///C:/Truetemp/pdfium001/UnitTestProject1/bin/Debug
LOG: Initial PrivatePath = NULL
Calling assembly : ClassLibrary1, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null.
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: C:\PROGRAM FILES (X86)\MICROSOFT VISUAL STUDIO\2017\COMMUNITY\COMMON7\IDE\EXTENSIONS\TESTPLATFORM\testhost.x86.exe.Config
LOG: Using host configuration file:
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config.
LOG: Post-policy reference: Patagames.Pdf, Version=4.4.6.2020, Culture=neutral, PublicKeyToken=60fd6cf9b15941cf
LOG: Attempting download of new URL file:///C:/Truetemp/pdfium001/UnitTestProject1/bin/Debug/Patagames.Pdf.DLL.
WRN: Comparing the assembly name resulted in the mismatch: Revision Number
ERR: Failed to complete setup of assembly (hr = 0x80131040). Probing terminated.

Edited by user Friday, August 30, 2019 12:24:39 PM(UTC)  | Reason: Not specified

sau002  
#2 Posted : Wednesday, September 4, 2019 4:23:54 AM(UTC)
sau002

Rank: Newbie

Groups: Registered
Joined: 8/17/2019(UTC)
Posts: 6
United Kingdom

Hi all,
Please, were you able to reproduce this?

Thanks,
Sau
Paul Rayman  
#3 Posted : Thursday, September 5, 2019 5:39:37 AM(UTC)
Paul Rayman

Rank: Administration

Groups: Administrators
Joined: 1/5/2016(UTC)
Posts: 789

Thanks: 1 times
Was thanked: 98 time(s) in 96 post(s)
Hi,

I'm not sure, but it looks like the TEST project cannot find the assembly file because the STANDARD20 project uses the new PackageReference format for the NuGet packages.
You can try one of the following:
1. Download the ZIP package instead of NuGet and add all the necessary files and dependencies to the STANDARD20 project manually.
Like described here: https://pdfium.patagames.com/help

or

2. You can implement the following workaround in the TEST project. I checked this way - works fine!
Code:
[TestClass]
public class UnitTest1
{
    [TestInitialize]
    public void Workaround()
    {
        AppDomain.CurrentDomain.AssemblyResolve += (s, e) =>
        {
            return System.Reflection.Assembly.LoadFile(@"c:\PatagamesPdf\\net461\Patagames.Pdf.dll");
        };
    }

    [TestMethod]
    public void TestMethod1()
    {
        var cl = new Class1();
        cl.test();
    }
}


3. In your TEST project migrate package.config to PackageReference and modify NSTANDARD20 project settings as follows

Code:
<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFramework>netstandard2.0</TargetFramework>
    <CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="pdfium.net.sdk" Version="4.15.2704">
      <PrivateAssets>all</PrivateAssets>
    </PackageReference>
  </ItemGroup>

</Project>

Edited by user Thursday, September 5, 2019 7:41:08 PM(UTC)  | Reason: Not specified

Users browsing this topic
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.