Aspose.PDF (SetLicense) does not work in Unit Test projects

I have a VS 2017 solution. The following does not work in the Unit Test project:


Aspose.Pdf.License license = new Aspose.Pdf.License();
if (File.Exists(“Aspose.Pdf.lic”))
{
license.SetLicense(“Aspose.Pdf.lic”);
}

I have created a sample solution, which has the same issue. Please see the attachment. Before running, change Aspose.Pdf.lic in both projects.
  • Console project will work
  • Unit Test project will NOT work
I get the following message when I run the Unit Test:

Test Name: TestMethod1
Test FullName: UnitTestProject1.UnitTest1.TestMethod1
Test Source: C:\Users\Harry\Desktop\ConsoleApp1\UnitTestProject1\UnitTest1.cs : line 12
Test Outcome: Failed
Test Duration: 0:00:00.1997196

Result StackTrace:
at System.AppDomain.nApplyPolicy(AssemblyName an)
at System.AppDomain.ApplyPolicy(String assemblyName)
at Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.AssemblyResolver.OnResolveInternal(Object senderAppDomain, ResolveEventArgs args, Boolean isReflectionOnly)
at Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.AssemblyResolver.OnResolve(Object sender, ResolveEventArgs args)
at System.AppDomain.OnAssemblyResolveEvent(RuntimeAssembly assembly, String assemblyFullName)
— End of inner exception stack trace —
at System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
at System.Reflection.RuntimeAssembly.nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
at System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef, Evidence assemblySecurity, RuntimeAssembly reqAssembly, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
at System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean forIntrospection)
at System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection)
at System.Reflection.Assembly.Load(String assemblyString)
at ..()
at .(Object , ResolveEventArgs )
at System.AppDomain.OnResourceResolveEvent(RuntimeAssembly assembly, String resourceName)
at System.Reflection.RuntimeAssembly.GetResource(RuntimeAssembly assembly, String resourceName, UInt64& length, StackCrawlMarkHandle stackMark, Boolean skipSecurityCheck)
at System.Reflection.RuntimeAssembly.GetManifestResourceStream(String name, StackCrawlMark& stackMark, Boolean skipSecurityCheck)
at System.Reflection.RuntimeAssembly.GetManifestResourceStream(String name)
at .(Assembly , String )
at .()
at .(Stream )
at .(String , Assembly )
at Aspose.Pdf.License.SetLicense(String licenseName)
at UnitTestProject1.UnitTest1.TestMethod1() in C:\Users\Harry\Desktop\ConsoleApp1\UnitTestProject1\UnitTest1.cs:line 16
Result Message:
Test method UnitTestProject1.UnitTest1.TestMethod1 threw exception:
System.IO.FileLoadException: Could not load file or assembly ‘zx_843a84cd29bf47d38dd548ac4c74c93e, PublicKeyToken=716fcc553a201e56’ or one of its dependencies. The parameter is incorrect. (Exception from HRESULT: 0x80070057 (E_INVALIDARG)) —> System.ArgumentException: The parameter is incorrect. (Exception from HRESULT: 0x80070057 (E_INVALIDARG))

Hi Harry,


Thanks for contacting support.

The UnitTest Project must include the reference of the main project. I have created a unit test project and added reference of main project to test the method and was unable to notice the issue. For your reference, I have attached an screenshot of the results over our end. Please try adding a UnitTest Project by right clicking on method, for which you want to create test method and Visual Studio will create a Unit Test Project with default settings.

In case of any further assistance, please feel free to contact us.


Best Regards,

I’m encountering this exact same issue and I am referencing the class library project that contains the code??

Thankx asad.ali.

I have followed your steps, and included the main project, but still have the same issue.

A)
Could you please make sure that you are also running VS 2017 (15.2)?

B)
Could you also please make sure that you use the following NuGet packages, and not the the libraries VS does reference in older VS installations:


C)
Have you tried runing my attached Solution. Did it work on your side?
Did you add the reference and it worked?

D)
Maybe you can provide your project, and I can verify it it works on my machine.

Thankx, Harry

cschmitt2000:
I’m encountering this exact same issue and I am referencing the class library project that contains the code??
Hi Chris,

Thanks for contacting support.

Can you please share your sample project, so that we can test the scenario in our environment. We are sorry for this inconvenience.

Just to make sure, there is one sample app in the first thread.

Hi Harry,


Thanks for writing back.

harry@ardmedia.com:
A)
Could you please make sure that you are also running VS 2017 (15.2)?

B)
Could you also please make sure that you use the following NuGet packages, and not the the libraries VS does reference in older VS installations:


We have tested the scenario with Visual Studio 2015 Community. We are setting up VS 2017 to test the scenario again and as soon as we complete testing the scenario, we will share our findings with you. Please be patient.

harry@ardmedia.com:
C)
Have you tried runing my attached Solution. Did it work on your side?
Did you add the reference and it worked?

D)
Maybe you can provide your project, and I can verify it it works on my machine.

We have tried your solution but it did not work, so we have created a new UnitTest Project through steps, which were shared above, and that worked fine. Please find attached sample project for your reference. You can change path of License File and add Aspose.Pdf for .NET assembly to run it at your end.


Best Regards,

Hi Asad.Ali

Any news on this thread: Aspose.PDF (SetLicense) does not work in Unit Test projects
How long do you think, do I have to be patient :wink:

Thankx for an update!


Harry

@harry.ardimedia

Thanks for your inquiry.

I am afraid that we have not received any updates from product team in this regard yet. We have recorded your concerns and intimated the relevant team about it. As soon as we have some definite updates, we will let you know. Please spare us little time.

We are sorry for the delay and inconvenience.


Best Regards,
Asad Ali

@harry.ardimedia

Thanks for your patience.

We have tested the scenario with latest version Aspose.Pdf for .NET 17.7, using specified NuGet Package(s) (i.e MSTest.TestAdapter" version=“1.1.18” and MSTest.TestFramework" version=“1.1.18”) and UnitTest was executed successfully. For your reference, I have attached a sample project. You may change the path to License file and try running the project.

In case of any further assistance, please feel free to let us know.

ConsoleApp1.zip (19.8 KB)


Best Regards,
Asad Ali

Hi Asad Ali

I have installed version 17.7 and I can confirm, that this version is working find with the MSTest components (1.1.18).

Thank you very much for your support!
Harry

@harry.ardimedia

Thanks for your feedback.

It is good to know that your issue has been resolved. Please keep using our API and in event of any other query, please feel free to contact us.


Best Regards,
Asad Ali

I also had this same problem with a Unit Test project. Upgrading to the latest version of Aspose resolved the issue.

Can you please help me how do i need to crate unit test project to read aspose license and set license

@nagasp

You can please download the sample project and build it at your end using latest version of the Aspose.PDF for .NET.

1 Like

A post was split to a new topic: Working with Aspose.Words in a unit test project