Unable to use Aspose.Pdf methods in MSTest Project

I am unable to use Aspose PDF methods in my MSTest methods.

Here is a rough overview of how the error is produced:

lic.SetLicense("Aspose.Total.lic");

Aspose.Pdf.Document doc = new Aspose.Pdf.Document(GetResourcePdfStream());
TestPdfStream = new MemoryStream();
doc.Save(TestPdfStream);

The above lines of code produce the following error only when I run this in an MSTest context

  Message: 

Initialization method dox42CoreUnitTests.PdfGeneratorUnitTests.SetUp threw exception. System.IO.FileLoadException: Could not load file or assembly β€˜{9a502237-0d97-41a6-89f5-699fc103b592}, PublicKeyToken=3e56350693f7355e’ 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)).

Stack Trace:
AppDomain.nApplyPolicy(AssemblyName an)
AssemblyResolver.OnResolveInternal(Object senderAppDomain, ResolveEventArgs args, Boolean isReflectionOnly)
AppDomain.OnAssemblyResolveEvent(RuntimeAssembly assembly, String assemblyFullName)
β€” End of inner exception stack trace β€”
RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef, Evidence assemblySecurity, RuntimeAssembly reqAssembly, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
RuntimeAssembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean forIntrospection)
RuntimeAssembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection)
Assembly.Load(String assemblyString)
˜2.Β’Β•(Object , ResolveEventArgs )
AppDomain.OnResourceResolveEvent(RuntimeAssembly assembly, String resourceName)
RuntimeAssembly.GetResource(RuntimeAssembly assembly, String resourceName, UInt64& length, StackCrawlMarkHandle stackMark, Boolean skipSecurityCheck)
RuntimeAssembly.GetManifestResourceStream(String name, StackCrawlMark& stackMark, Boolean skipSecurityCheck)
RuntimeAssembly.GetManifestResourceStream(String name)
.œ(Assembly , String )
.ΒžΒƒΒ—(String , Assembly )
.Β™(String , Assembly , Boolean )
.Β•(String , Assembly )
License.SetLicense(String licenseName)
PdfGeneratorUnitTests.SetUp() line 29

Now, I was unable to find any good solutions for this issue on the internet other than upgrading Aspose product versions.

I am trying to get unit tests working with Aspose.Pdf version 9.4.0.0

Is this version of Aspose.Pdf simply too old to be used in an MSTest context? I have tried with the latest Aspose.Pdf version (23.9.0.0), which has worked.

It would be really helpful to know, whether Aspose.Pdf 9.4.0.0 methods can be used in unit testing.

Thanks for your help in advance!

@diegoschleis

We are afraid that you are using quite older version of the API in which a lot of classes have been discontinued and many enhancements have already been made since then. We provide support on the basis of the latest version of the API. Therefore, we request you please use the latest available version of the API and if any issue occurs, feel free to let us know. We will further proceed to assist you accordingly.

Thank you for the quick response.

I am afraid it is pretty hard to explain why we use such an old Aspose version. We have a legacy code base in general which uses legacy versions. We are in the process of refactoring said code base and have hit a hurdle when it comes to unit testing methods that use the Aspose API.

What would be options for more extensive support perhaps in a legacy context?

If there are no options, would it be possible for you to give a definitive yes or no on whether unit testing is possible with the version stated in my support request?

The issue I am describing is not really pressing, however, it would be useful to have some kind of answer, so we can keep this in mind for our refactoring effort.

Again, thank you for your help. I know my request might be a bit too much to ask.

@diegoschleis

It is quite hard to confirm if this much older version would be compatible with the unit tests. Even unit test feature was not available in the visual studio back then at the time this version used to be maintained. By the passage of time, the API has been being upgraded along with other upgrades in .NET Frameworks as well as the IDEs. Therefore, we would not recommend to use older versions of the API and expect them to run with today’s (upgraded and latest) IDEs.

1 Like

Thanks for your help.

We will keep this information in mind while refactoring our code base.

You can close this ticket :slight_smile: