Problem with licensing

I'm in the process of updating to a newer version of aspose in our web applications, to be able to use the newer functions..

The odd part is that while i can make the program work perfectly by referencing the merged .dll's, or placing them in the bin folder(s); But as soon as i place them in the GAC, they stop working completely and give 2 exceptions.

Exception 1: Could not load file or assembly 'Aspose.Pdf, Version=7.2.0.0 ... ' or one of its dependencies. The system cant find the file specified.

Exception 2: Failed to set licence for . (This is when i try to call Aspose.Pdf.License.SetLicense function.)

So to sum up, the application works perfectly with the older variants of aspose (it uses merged dll's in the GAC), and the newer only works if the DLL's arent in the GAC.. And im at a loss as to why.

Any pointers/tips as to what to do to make it work?

Hi Lars,

<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Please share the details regarding your system environment i.e. OS, 32 bit or 64 bit machine, .NET Framework and the code segment for setting the embedded license. This will help us in testing and identifying the cause of the issue.

Sorry for the inconvenience,

The machines i've tested on are Win7 32bit, .net framework 3,5 asp 2

And Windows server 2003R2, 64 bit. Asp.Net 2

And the code segment as follows:

Old code:

private void SetLicense()
{
try
{
// Set license for Aspose.Pdf.Kit
using (Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream ("CodeKnox.DAS.License.lic"))
{
Aspose.Pdf.Kit.License license = new Aspose.Pdf.Kit.License();
if (stream != null && stream.Length > 0)
license.SetLicense(stream);
else
throw new Exception("Failed to get resource");
}
}
catch (Exception ex)
{
throw new LicenseException(this.GetType(), this, "Failed to set license for DAS.Pdf", ex);
}
}

New code:

private void SetLicense()
{
try
{
using (Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream ("CodeKnox.DAS.License.lic"))
{
license = new Aspose.Pdf.License();
if (stream != null && (stream.Length > 0))
license.SetLicense(stream);
else
throw new Exception("Failed to get resource");
}
}
catch (Exception ex)
{
throw new LicenseException(this.GetType(), this, "Failed to set license for DAS.Pdf", ex);
}
}

Argh, formatting seems not to follow and the indenting wont be more readable..

My apologies for that.

//ps. And for the wrong code being posted.

Hi Lars,

<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thank you for the details.

Please confirm that you are using Aspose.Pdf for .NET or Aspose.Pdf.Kit for .NET? As I can see from your code, you are setting up the license for Aspose.Pdf.Kit for .NET but as per the details in your first post, you are facing the issue in Aspose.Pdf for .NET v7.2. Please confirm and make sure that you are setting the license for Aspose.Pdf for .NET instead of Aspose.Pdf.Kit for .NET.

Please do let us know about the above so we can further look into this issue. For setting license of Aspose.Pdf for .NET, you can also refer to the following documentation links:

Using File or Stream object

Using as Embedded resource

Sorry for the inconvenience,

Hi,

As mentioned before, the newer variant is what i tried the before (above),i just tried the example you linked to:

Aspose.Pdf.License license = new Aspose.Pdf.License();
license.SetLicense("MergedAPI.Aspose.Total.lic");
license.Embedded = true;

Same issue there, works fine 'til i Put it in the GAC, then same errors as above.

Hi Lars,


We are trying to replicate this issue at our end and will get back to you soon. We are sorry for this inconvenience.

Hi Lars,<?xml:namespace prefix = o ns = “urn:schemas-microsoft-com:office:office” /><o:p></o:p>

<o:p> </o:p>

Sorry for a delay in response.<o:p></o:p>

<o:p> </o:p>

I tried to replicate your issue by adding my license file
with my custom dll to GAC and then apply the license using the below code and I
am unable to notice any problem. It works fine with the below code and license
is applied successfully.<o:p></o:p>

<o:p> </o:p>

Stream licStream = null;<o:p></o:p>

<o:p> </o:p>

Assembly assembly = Assembly.Load(“HelloWorld, Version=1.0.0.0, Culture=neutral,
PublicKeyToken=985ed5d9af42cd6f”
);<o:p></o:p>

<o:p> </o:p>

string[] resourceNames =
assembly.GetManifestResourceNames();<o:p></o:p>

<o:p> </o:p>

foreach (string resourceName in resourceNames)<o:p></o:p>

{<o:p></o:p>

<o:p> </o:p>

if
(resourceName.IndexOf(“Aspose.Total.lic”)
!= -1)<o:p></o:p>

<o:p> </o:p>

licStream =
assembly.GetManifestResourceStream(resourceName);<o:p></o:p>

<o:p> </o:p>

}<o:p></o:p>

<o:p> </o:p>

if (licStream == null)<o:p></o:p>

<o:p> </o:p>

throw new ApplicationException(“Error in Loading License Stream”);<o:p></o:p>

<o:p> </o:p>

Aspose.Pdf.License lic = new
Aspose.Pdf.License();<o:p></o:p>

<o:p> </o:p>

lic.SetLicense(licStream);<o:p></o:p>

<o:p> </o:p>

//Create pdf
document<o:p></o:p>

Aspose.Pdf.Generator.Pdf pdf1 = new
Aspose.Pdf.Generator.Pdf();<o:p></o:p>

<o:p> </o:p>

//Add a
section into the pdf document<o:p></o:p>

Aspose.Pdf.Generator.Section sec1 = pdf1.Sections.Add();<o:p></o:p>

<o:p> </o:p>

//Add a text
paragraph into the section<o:p></o:p>

sec1.Paragraphs.Add(new Aspose.Pdf.Generator.Text(“Hello World”));<o:p></o:p>

<o:p> </o:p>

//Save the
document<o:p></o:p>

pdf1.Save(@“D:\AP Data\October2012\HelloWorld.pdf”);<o:p></o:p>

<o:p> </o:p>

It seems that the issue is either with your assembly or
as GetExecutingAssembly() returns the assembly
of currently executed code, it is not returning the required assembly. Please
try the above sample code and check if it works fine for you to confirm the
issue is not with the latest version of Aspose.Pdf for .NET.<o:p></o:p>

<o:p> </o:p>

Please do let us know
regarding the results.<o:p></o:p>

<o:p> </o:p>

Sorry for the inconvenience,<o:p></o:p>

Thoroughly tried that one too, and got the same response. (With the inner exception: "Attempted to read or write protected memory. This is often an indication that other memory is corrupt)

Also tried to just have the license as a string and send it (streamed), works fine as long as i dont put the dll into the GAC.

Same with reading the license file directly, works fine 'til i put it (the merged DLL) into the GAC.

And if not mentioned before, all the other modules i use (Aspose.Words, Aspose.Imaging, Aspose.Slides, aspose.cells & aspose.email) work fine... With the same ways of setting the license as i use for Aspose.pdf...

Is there some kind of difference in how Aspose.Pdf handles licencing, and if so, how can i get around it?

Hi Lars,<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

It is very strange issue because the code I shared above works fine for me when I access the license through GAC. I would request you to create a sample DLL (which I can register to GAC) and create a sample application (which I can use to generate the issue) and share with us. This will help us identify the cause of the issue.

Sorry for the inconvenience,

The problem got resolved with a work-around, thanks for your help.

Hi Lars,<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thank you for the feedback.

We are pleased to know that you are able to resolve your issue at your end. We will appreciate it if you can share the workaround you implemented with us, so we might suggest the workaround to some other customer in case a similar problem is reported.

Please feel free to contact support in case you need any further assistance.

Thank You & Best Regards,