Hi,
I testing aspose .net package in our application. We weren’t able to add the licens einto our code. We used the code below. Can someone please let me know whats my mistake? We also tried the suggestion in the link and failed.
string templatesFolder = (@“C:\Users\Eren\source\repos\OCRiverse\OCRiverse”);
string dataDir = templatesFolder;
string fileName = Path.Combine(dataDir, “Aspose.TotalProductFamily.lic”);
Aspose.Pdf.License license = new Aspose.Pdf.License();
Aspose.Words.License license2 = new Aspose.Words.License();
Aspose.Cells.License license3 = new Aspose.Cells.License();
Aspose.Html.License license4 = new Aspose.Html.License();
using (FileStream stream = File.Open(fileName, FileMode.Open))
{
license.SetLicense(stream);
license2.SetLicense(stream);
license3.SetLicense(stream);
license4.SetLicense(stream);
}
aspose lisans c#.PNG (14.5 KB)
@Cengizkurban
Summary
The license file is being read correctly for the first Aspose component, but the same FileStream is reused for the remaining components. After the first SetLicense call the stream’s position is at the end of the file, so the subsequent calls receive an empty stream and the components stay in evaluation mode.
Why it happens
License.SetLicense(Stream) consumes the entire stream.
- When the same
FileStream instance is passed to another component, its Position is already at EOF, so nothing is read.
- The code does not check
License.IsLicensed, which Aspose recommends to verify that a component is actually licensed.
What to do next
- Use a fresh stream or the file‑path overload for each component – this guarantees the license data is read from the beginning each time.
using System;
using System.IO;
using Aspose.Pdf;
using Aspose.Words;
using Aspose.Cells;
using Aspose.Html;
string licPath = @"C:\Users\Eren\source\repos\OCRiverse\OCRiverse\Aspose.TotalProductFamily.lic";
// PDF
new Aspose.Pdf.License().SetLicense(licPath);
// Words
new Aspose.Words.License().SetLicense(licPath);
// Cells
new Aspose.Cells.License().SetLicense(licPath);
// HTML
new Aspose.Html.License().SetLicense(licPath);
If you prefer the stream overload, create a new FileStream for each call instead of reusing one.
- Verify that each component is licensed using the
IsLicensed property, as suggested by Aspose documentation.
var pdfLicense = new Aspose.Pdf.License();
pdfLicense.SetLicense(licPath);
Console.WriteLine("PDF licensed: " + pdfLicense.IsLicensed);
var wordsLicense = new Aspose.Words.License();
wordsLicense.SetLicense(licPath);
Console.WriteLine("Words licensed: " + wordsLicense.IsLicensed);
var cellsLicense = new Aspose.Cells.License();
cellsLicense.SetLicense(licPath);
Console.WriteLine("Cells licensed: " + cellsLicense.IsLicensed);
var htmlLicense = new Aspose.Html.License();
htmlLicense.SetLicense(licPath);
Console.WriteLine("HTML licensed: " + htmlLicense.IsLicensed);
Each line should output True. If any output is False, double‑check the .lic file and its compatibility with the referenced Aspose libraries.
- Validate the license file itself
- Open the
.lic file in a text editor – it should be an XML document containing your license key.
- Ensure the file was generated for a Total Product Family license and that it covers all the Aspose products you are using.
- Verify that the file is accessible (correct path, read permissions).
- Troubleshoot remaining issues
- Wrap each
SetLicense call in a try / catch block and log any exception; this can reveal permission problems or corrupted files.
- Confirm that the application’s runtime has permission to read the folder containing the license.
- If you have recently upgraded any Aspose component, consider downloading a fresh Total Product Family license from your Aspose account and replacing the existing
.lic file.
Following these steps should reliably apply the Total Product Family license to all four Aspose components in your C# project.
Note: The Aspose documentation recommends checking License.IsLicensed to confirm that a license has been applied successfully.
I could not fully verify this explanation against the retrieved sources. Please double-check the behaviour in your environment and confirm the exact SDK/version.
@Cengizkurban,
Could you please try to update your code segment to:
string templatesFolder = (@“C:\Users\Eren\source\repos\OCRiverse\OCRiverse”);
string dataDir = templatesFolder;
string fileName = Path.Combine(dataDir, “Aspose.TotalProductFamily.lic”);
Aspose.Pdf.License license = new Aspose.Pdf.License();
Aspose.Words.License license2 = new Aspose.Words.License();
Aspose.Cells.License license3 = new Aspose.Cells.License();
Aspose.Html.License license4 = new Aspose.Html.License();
using (FileStream stream = File.Open(fileName, FileMode.Open))
{
license.SetLicense(stream);
stream.Position = 0;
license2.SetLicense(stream);
stream.Position = 0;
license3.SetLicense(stream);
stream.Position = 0;
license4.SetLicense(stream);
}
......
Let us know if you still find the issue.