How to activate license for the latest aspose total .net

Dear aspose team,

I just got the license for the latest aspose total and it seems the way of activating it has changed from what we had before.
Could you please be so kind and help how to activate license once without going over all used products.

internal class AsposeLicenseLoader : IHostedService
    {
        private static readonly string[] AsposeLicenseProducts =
        {
            $"{nameof(Aspose)}.{nameof(Aspose.CAD)}.{nameof(Aspose.CAD.License)}, {nameof(Aspose)}.{nameof(Aspose.CAD)}",
            $"{nameof(Aspose)}.{nameof(Aspose.Imaging)}.{nameof(Aspose.Imaging.License)}, {nameof(Aspose)}.{nameof(Aspose.Imaging)}",
            $"{nameof(Aspose)}.{nameof(Aspose.Font)}.{nameof(Aspose.Font.License)}, {nameof(Aspose)}.{nameof(Aspose.Font)}",
        };

        private const string _asposeLicense = "here the code is hidden for security reasons";

        public AsposeLicenseLoader(ILogger<AsposeLicenseLoader> logger)
        {
            try
            {
                using var ms = new MemoryStream(Convert.FromBase64String(_asposeLicense));
                using var deflator = new DeflateStream(ms, CompressionMode.Decompress);
                using var data = new MemoryStream();
                deflator.CopyTo(data);

                foreach (var product in AsposeLicenseProducts)
                {
                    data.Position = 0;

                    var licenseType = Type.GetType(product);
                    var setLicenseMethod = licenseType?.GetMethod(
                        nameof(Aspose.Imaging.License.SetLicense),
                        new[] { typeof(Stream) }
                    );

                    if (licenseType == null || setLicenseMethod == null)
                        return;

                    var loader = Activator.CreateInstance(licenseType);
                    setLicenseMethod.Invoke(loader, new[] { data });
                }
            }
            catch (Exception)
            {
                logger.LogError("Could not load license for extended formats");
            }
        }

image.png (265.5 KB)

@VartanSaakian Hello! Thank you for your interest in our product. Unfortunately, while the Total license allows you to purchase a bundle of our products at once, these are separate products, so it’s not possible to install a license for all of them in a single step. Also, when possible, it’s recommended to avoid using reflection for license installation to prevent performance degradation. Here you can find documentation and examples related to licensing:

Hey @Alexey.Karpenko thanks for your help.
I tried to re-write based on your suggestion but it endup with exception
Please the the picture bellow:
Steps i am doing → converting *.lic file to Base64 string → create stream → path to lib.
image.png (88.2 KB)

@VartanSaakian,
Hello.
Could you please share your .lic file via private messages like it is shown here?

1 Like

@oleksii.gorokhovatskyi all done huge thanks for your help.

@VartanSaakian,
please test if this is useful:

var ms = new MemoryStream(Convert.FromBase64String(file));

Aspose.Imaging.License ImagingLicense = new Aspose.Imaging.License();
Aspose.CAD.License CADLicense = new Aspose.CAD.License();

ImagingLicense.SetLicense(ms);

ms.Position = 0;

CADLicense.SetLicense(ms);

Tested with the latest releases Aspose.CAD (24.12), Aspose.Imaging (25.2) and your license file.

1 Like

@oleksii.gorokhovatskyi seems to be working well. sorry i am an idiot reading stream once and did not return it to 0 after :man_facepalming:
My fault.
Huge thanks!

1 Like

@VartanSaakian,
we are happy to help :slight_smile: