We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Null reference when using SetLicence

Hello,


I’m facing an issue when setting license that reproduces every while and no i don’t have a clear scenario for reproduction.
I’m using the license as embedded resource

below is my code used :

public void SetLicence(
{
            string license = “Aspose.Total.Product.Family.lic”;
this.SetLicence(license);
}
    <span style="color:blue;">public</span> <span style="color:blue;">void</span> SetLicence(<span style="color:blue;">string</span> license)
    {
        <span style="color:blue;">using</span> (System.Security.Principal.<span style="color:#2b91af;">WindowsImpersonationContext</span> ctx = System.Security.Principal.<span style="color:#2b91af;">WindowsIdentity</span>.Impersonate(System.<span style="color:#2b91af;">IntPtr</span>.Zero))
        {
            Aspose.Imaging.<span style="color:#2b91af;">License</span> licenseImaging = <span style="color:blue;">new</span> Aspose.Imaging.<span style="color:#2b91af;">License</span>();
            licenseImaging.SetLicense(license);

            Aspose.Words.<span style="color:#2b91af;">License</span> licenseWord = <span style="color:blue;">new</span> Aspose.Words.<span style="color:#2b91af;">License</span>();
            licenseWord.SetLicense(license);

            Aspose.Slides.<span style="color:#2b91af;">License</span> licenseSlide = <span style="color:blue;">new</span> Aspose.Slides.<span style="color:#2b91af;">License</span>();
            licenseSlide.SetLicense(license);

            Aspose.Pdf.<span style="color:#2b91af;">License</span> licensePdf = <span style="color:blue;">new</span> Aspose.Pdf.<span style="color:#2b91af;">License</span>();
            licensePdf.SetLicense(license);

            Aspose.Cells.<span style="color:#2b91af;">License</span> licenseCells = <span style="color:blue;">new</span> Aspose.Cells.<span style="color:#2b91af;">License</span>();
            licenseCells.SetLicense(license);

            Aspose.Diagram.<span style="color:#2b91af;">License</span> licenseDiagram = <span style="color:blue;">new</span> Aspose.Diagram.<span style="color:#2b91af;">License</span>();
            licenseDiagram.SetLicense(license);
        }

    }</pre><pre style="background-color: white;"><font face="Times New Roman">I'm getting the following error: Object reference not set to an instance of an object.</font></pre><pre style="background-color: white;"><font face="Times New Roman">After an iisreset everything works normally again</font></pre><pre style="background-color: white;"><font face="Times New Roman">Any advice? </font></pre><pre style="background-color: white;"><font face="Times New Roman">Thank you<span style="font-size: 13px;"> </span></font></pre><pre style="font-family: Consolas; font-size: 13px; background-color: white; background-position: initial initial; background-repeat: initial initial;"><br></pre></div>

Hi Hiba,


Thanks for contacting support.

I would like to answer from Aspose.Pdf for .NET perspective. Please try using following code lines to use the license file as an embedded resource. In case you still face any problem, please feel free to contact.

[C#]

// create a Pdf license object
Aspose.Pdf.License lic = new Aspose.Pdf.License();
// specify the license file name along with Default namespace of application
lic.SetLicense(“MergedAPI.Aspose.Total.lic”);
// set the value to indicate that license will be embedded in the application
lic.Embedded = true;


Where MergedAPI is the default Namespace of my project (Right Click Solution in Solution Explorer
and select Properties. You will see the page with Default Namespace information
).

Hi,


So i should replace “Aspose.Total.Product.Family.lic” by “MergedAPI.Aspose.Total.lic” for Aspose.Pdf and that should work?
And the namespace idea is not clear can you please clarify that?
And what about the other libraries ? Do I need to have a licence for each used product?

Thank you

hri:
So i should replace “Aspose.Total.Product.Family.lic” by “MergedAPI.Aspose.Total.lic” for Aspose.Pdf and that should work?

Hi Hiba,

If your license file name is Aspose.Total.Product.Family.lic, you need to use MergedAPI.Aspose.Total.Product.Family.lic as license name.
hri:
And the namespace idea is not clear can you please clarify that?
Please visit the following link for further details on Using as Embedded Resource
hri:
And what about the other libraries ? Do I need to have a licence for each used product?
If you have Aspose.Total.Product.Family.lic for Aspose.Total for .NET products, then this single license file can be used with all the products under Aspose.Total for .NET umbrella. However you need to explicitly initialize the license for individual product, like you did you your code snippet.

Hi,


When i’m setting MergedAPI.Aspose.Total.Product.Family.lic as my license name an exception in thrownCannot find license ‘MergedAPI.Aspose.Total.Product.Family.lic’”, am i missing something?
The license file name i have is: Aspose.Total.Product.Family.lic
The Embedded property is only for aspose.PDF license object, the other products can’t have an embedded resource or if i set the pdf one as to true will be enough?
can you please clarify more how to avoid the null reference error i’m getting every once in a while?

Thank you

hri:
When i'm setting MergedAPI.Aspose.Total.Product.Family.lic how to as my license name an exception in thrown "Cannot find license 'MergedAPI.Aspose.Total.Product.Family.lic'", am i missing something?
The license file name i have is: Aspose.Total.Product.Family.lic
Hi Hiba,

Thanks for sharing the details and sorry for the delayed response.

When using earlier stated approach, the license file must be included as embedded resource and Default namespace of application should be provided when initializing the license for Aspose.Pdf for .NET. Please ensure that the license (Aspose.Total.Product.Family.lic) is included as an embedded resource in solution.

hri:
The Embedded property is only for aspose.PDF license object, the other products can't have an embedded resource or if i set the pdf one as to true will be enough?
For every API, you need to explicitly initialize the license. However concerning to your query on embedded property for other API's, I have asked my fellow workers to answer this query.

We are sorry for this inconvenience.

Hi Hiba,


Adding more to my earlier comments, can you please add some breakpoints in your code while initializing license for individual API and determine the code line causing this exception.

Hi Hiba,


I have observed the requirement for property to tell if the license used is embedded inside application for Aspose.Slides on my end. I regret to share that at present the requested property is unavailable in Aspose.Slides. I have created an issue with ID SLIDESNET-35194 in our issue tacking system to further investigate this on our end. This thread has been linked with the issue so that you may be automatically notified once the support will be available.

We are sorry for your inconvenience,

Hi Hiba,


hri:
The Embedded property is only for aspose.PDF license object, the other products can’t have an embedded resource or if i set the pdf one as to true will be enough?
Thank you for reporting us about the embedded property. At the moment, it is not available. I’ve logged this feature request in our issue tracking system under ticket id DIAGRAMNET-50061 for Aspose.Diagram. Your request has been linked to this issue. We will notify you once it is supported. We’re sorry for your inconvenience.