License initialization errors in Aspose.Pdf 4.7 & 4.9

I'm having trouble getting the 4.9 version to accept my license. Here's my class library code with notes:

namespace AsposeTestLib
{
public static class AsposeManager
{
const string LICENSE_FILE = "AsposeTestLib.Resources.Aspose.Total.lic";

private static readonly System.Reflection.Assembly _assembly = typeof(AsposeManager).Assembly;
private static readonly Aspose.Pdf.License _asposePdfLicense = new Aspose.Pdf.License();

//
// Aspose.Pdf.dll (4.9) - Fails with TypeInitializationException / VerificationException : Target=32 & 64|Release, OS=64bit, .Net 4.0 Full
// Aspose.Pdf.dll (4.7) - Works!
//
public static void InitializeWithStream()
{
using (var stream = _assembly.GetManifestResourceStream(LICENSE_FILE))
{
if (stream != null)
_asposePdfLicense.SetLicense(stream);
else
throw new System.ApplicationException(System.String.Format("Unable to find Aspose license resource stream '{0}' in assembly '{1}'", LICENSE_FILE, _assembly.GetName()));
}
}

//
// Aspose.Pdf.dll (4.9) - Fails with TypeInitializationException / VerificationException : Target=32 & 64|Release, OS=64bit, .Net 4.0 Full
// Aspose.Pdf.dll (4.7) - Fails with FileNotFoundException 'LICENSE_FILE' : Target=64 only|Release, OS=64bit, .Net 4.0 Full
// It only seems to fail outside of the debugger on this one.
//
public static void InitializeWithPath()
{
_asposePdfLicense.SetLicense(LICENSE_FILE);
}
}
}

Here is the test application that runs it:

namespace AsposeTest
{
class Program
{
private const string TEST_PDF = @"C:\HelloWorld.pdf";

static void Main()
{
System.Console.WriteLine("Current process is {0}-bit.", System.IntPtr.Size * 8);

//
// INITIALIZE ASPOSE PDF WITH LICENSE
//
AsposeTestLib.AsposeManager.InitializeWithPath();

System.Console.WriteLine("License manager successfully initialized.");

//
// CREATE A TEST PDF
//
CreateTestPdf();

if (!System.IO.File.Exists(TEST_PDF))
{
throw new System.IO.FileNotFoundException("File not found", TEST_PDF);
}

System.Console.WriteLine("Test PDF file created successfully.");

//
// END
//
System.Console.WriteLine();
System.Console.WriteLine("Test successful");
System.Console.ReadLine();
}

private static void CreateTestPdf()
{
var pdf = new Aspose.Pdf.Pdf();
var section = pdf.Sections.Add();

section.Paragraphs.Add(new Aspose.Pdf.Text("Hello World!"));

pdf.Save(TEST_PDF);
}
}
}

Here are the two different stack traces I'm getting. For the 4.7 issue:

Unhandled Exception: System.IO.FileNotFoundException: Cannot find license 'AsposeTestLib.Resources.Aspose.Total.lic'.
at x21e4a7ad326d8315.x220f433da4115056.xde6236852622c268(String x1c1fc72fe1a3b4ea, Assembly x39e0a96279c40baa, Boolean x77c11057a70ce853)
at x21e4a7ad326d8315.x220f433da4115056.x7d0214bf69711dd9(String x1c1fc72fe1a3b4ea, Assembly x5807f920b6fc67c4)
at Aspose.Pdf.License.SetLicense(String licenseName)
at AsposeTest.Program.Main() in C:\Users\myname\Documents\Visual Studio 2010\Projects\AsposeTest\AsposeTest\Program.cs:line 21

For the 4.9 issues:

Unhandled Exception: System.TypeInitializationException: The type initializer for '☺.♣' threw an exception. ---> System.Security.VerificationException: Operation could destabilize the runtime.
at (Object , String )
at ☺.♣..cctor()
--- End of inner exception stack trace ---
at ☺.♣.⌂(Int32 )
at Aspose.Pdf.License.SetLicense(String licenseName)
at AsposeTest.Program.Main() in C:\Users\myname\Documents\Visual Studio 2010\Projects\AsposeTest\AsposeTest\Program.cs:line 17

Sorry about the formatting, I couldn't figure out how to make it look nicer. We are rolling back our library to 4.7 and the InitializeWithStream method to get our clients working, but I wanted to understand why we aren't able to upgrade to the 4.9 version.

Thank you in advance!

Hi,

Thanks for using our products.

I have tested the scenario using following code snippet with Aspose.Pdf for .NET 4.9.0 over Windows7 Enterprise 64Bit in a Windows Desktop application developed in Visual Studio 2008 and I am unable to notice any problem.

In order to replicate the scenario, I have included the license file as an existing item at project root level and mark it as Embedded Resource under properties window. In my scenario, I have a project named WindowsTemplate and the DefaultNamespace is WindowsTemplate. So the name will be identified as WindowsTemplate.Aspose.Total.Product.Family.lic. I have used the following code snippet and I am unable to notice the problem. Can you please share some details regarding your working environment.

[C#]

const string LICENSE_FILE = "WindowsTemplate.Aspose.Total.Product.Family.lic";
private static readonly System.Reflection.Assembly _assembly = typeof(Form1).Assembly;
private static readonly Aspose.Pdf.License _asposePdfLicense = new Aspose.Pdf.License();

private void button1_Click(object sender, EventArgs e)
{
InitializeWithStream();
Pdf pdf = new Pdf();
Aspose.Pdf.
Section sec = pdf.Sections.Add();
sec.Paragraphs.Add(new Text("Hello World"));
pdf.Save(@"d:/pdftest/MyLicenseTest.pdf");
}

public static void InitializeWithStream()
{
using (var stream = _assembly.GetManifestResourceStream(LICENSE_FILE))
{
if (stream != null)
_asposePdfLicense.SetLicense(stream);
else
throw new System.ApplicationException(System.String.Format("Unable to find Aspose license resource stream '{0}' in assembly '{1}'", LICENSE_FILE, _assembly.GetName()));
}
}

Thank you for your response. My development environment is vs2010/.net 4.0. My feeling is that this is .net 4.0 related and possibly an obfuscation issue. The two bits of code above are a complete stand-alone test project (an .exe and a .dll) that I can get to fail every time using the .net 4.0 framework. In the code comments of the first bit, I've listed the target processor, os, and framework that I can't make work for each method call.

The reason I initially posted is because the InitializeWithPath method was working in .net 3.5/aspose 4.7 and started failing after we moved to .net 4.0/aspose 4.7.

I've also noticed the size difference between the 4.7 and 4.9 Aspose.Pdf.dll. Is that due to the obfuscation? Can you tell me which obfuscation tool you are employing? Just to be thorough, was your test run the production/obfuscated library?

It may have nothing to do with the obfuscation at all. I just don't want to rule anything out. It's more of a gut feeling than anything else.

I do appreciate your help. Can you run the code I posted in the .net 4.0 framework?

Hi,

We are working over this query and will get back to you soon. We apologize for the delay and inconvenience.

In my scenario, I’m not using the assembly compiled for the .net 4.0 client profile. Sorry, I had forgotten to mention that.

Hi,

Thanks for sharing the license file.

I have tested the scenario and I am able to notice the problem that Aspose.Pdf for .NET 4.9.0 is generating an exception when using the license file that you have shared in an application targetting .NET Framework 4.0. For the sake of correction, I have logged this problem as PDFNET-23910 in our issue tracking system. We will further look into the details of this problem and will keep you updated on the status of correction.

We apologize for your inconvenience.

Hi,

Adding more to my previous comments, the issue seems to be related to obfuscation settings & security enhancement in .NET 4.0, but we are going to investigate the reasons in further details. The size may be different because we used to use another obfuscation tool and we now we are using SmartAssembly.

All our tests were passed for production library, but I am afraid this particular case got ignored. However, we will add appropriate checks for this issue once the investigation regarding problem is completed. In case you have any further query, please feel free to contact.

I appreciate your help. Thank you!

The issues you have found earlier (filed as 23910) have been fixed in this update.


This message was posted using Notification2Forum from Downloads module by aspose.notifier.
(1)