Hi,
I am trying to start a new project in .net 8 and I have the following code
try
{
var license = new Aspose.Pdf.License();
var assembly = Assembly.GetExecutingAssembly();
var licenseFileName = “PrintServiceAPI.Aspose.Pdf.lic”; // Confirmed path
using (Stream licenseStream = assembly.GetManifestResourceStream(licenseFileName))
{
if (licenseStream == null)
{
throw new FileNotFoundException($"License file '{licenseFileName}' not found as embedded resource.");
}
license.SetLicense(licenseStream); // This line is where the exception happens
}
}
catch (Exception ex)
{
Console.WriteLine($“Error loading Aspose license: {ex.Message}”);
if (ex.InnerException != null)
{
Console.WriteLine($“Inner exception: {ex.InnerException.Message}”);
}
}
The file is definitely exists but it still comes up with an error when license.SetLicense(licenseStream)
is executed. I am using version 20.9.0
The exception message is ‘Exception_WasThrown’’
Could you advise on how to resolve this please?
Thanks
Ryan.
@ryanleeRDY
It seems you are encountering an issue while trying to load the Aspose license in your .NET 8 project. The exception message ‘Exception_WasThrown’ indicates that there might be a problem with how the license is being set.
Here are a few steps you can take to troubleshoot and resolve the issue:
-
Check License File Path: Ensure that the license file is correctly embedded as a resource in your project. You can verify this by checking the properties of the license file in your project and ensuring that the “Build Action” is set to “Embedded Resource”.
-
Use Absolute Path: Instead of using an embedded resource, you can try loading the license file using an absolute path. For example:
license.SetLicense("C:\\path\\to\\your\\license\\PrintServiceAPI.Aspose.Pdf.lic");
-
Check License File Validity: Make sure that the license file is valid and not expired. You can do this by opening the license file in a text editor and checking the validity dates.
-
Catch Specific Exceptions: Modify your catch block to catch specific exceptions related to license loading. This can provide more insight into what might be going wrong:
catch (Aspose.Pdf.LicenseException lex)
{
Console.WriteLine($"License error: {lex.Message}");
}
catch (FileNotFoundException fnfEx)
{
Console.WriteLine($"File not found: {fnfEx.Message}");
}
catch (Exception ex)
{
Console.WriteLine($"Error loading Aspose license: {ex.Message}");
}
-
Check for Updates: Since you are using version 20.9.0, consider checking if there are any updates or patches available for the Aspose.PDF library that might address this issue.
By following these steps, you should be able to identify the cause of the problem and successfully load the license. If the issue persists, please provide any additional error messages or context that may help in diagnosing the problem further.
Hey Thanks for the prompt reply!
We already have an application in .Net Framework 4.8 using the same license file so I don’t think it’s a license issue. Unless the license file is strictly for .Net Framework and not .Net 8.0
I have checked the license file and it’s definitely embedded.
I even changed the code as the following:
foreach (var resource in assembly.GetManifestResourceNames())
{
if (resource.EndsWith(licenseFileName))
{
using (Stream licenseStream = assembly.GetManifestResourceStream(resource))
{
if (licenseStream != null)
{
license.SetLicense(resource);
}
else
{
throw new FileNotFoundException($“License file ‘{licenseFileName}’ not found as embedded resource.”);
}
}
}
}
And confirmed that the resource exists using debugger.
I have also tried directly loading the license file and it comes up with same exception.
Is there anything else you could adivse?
Thanks
Ryan.
@ryanleeRDY
The issue is related to the API version. You are trying to use an older version of the API that does not support and is not compatible with .NET 8.0. You need to upgrade to the latest version of the API in order to use it with .NET 8.0.
@asad.ali
Thanks for you reply!
I found the package info link and found the .net 8.0 is compatible, so this list is incorrect?
image.png (28.4 KB)
Thanks again for your time!
Ryan.
@ryanleeRDY
This information is fetched on the basis of the latest version available on the site. Therefore, the .NET 8.0 support is available in the API however, it was added in 24.5 version.
@asad.ali
Thanks for the clarification. Have a great day!