GIS Converter -Unit Tests Projects -Set Aspose License.

Dani_S 5,261 Reputation points
2025-12-17T08:25:47.6266667+00:00

Hi Michel,

Thank you very much for your help !!!

I implemented all your remarks from ticket:

https://learn.microsoft.com/en-us/answers/questions/5658212/gis-cli-commands

1,How do I set the Aspose license to all my unit tests in one place ?

2.This the code I used in GisConverter.ConsoleApp

// Apply license once at startup

if (!AsposeLicenseManager.ApplyLicense())

{

Console.Error.WriteLine("⚠️ Failed to apply Aspose license.  Conversions may fail or produce watermarked output.");

Environment.Exit((int)ExitCode.AppError);
}

6.This code I used for manual testings is it a good practice?

warnings.txt

Thanks in advance,

Developer technologies | C#
Developer technologies | C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
0 comments No comments
{count} votes

Answer accepted by question author
  1. Michael Le (WICLOUD CORPORATION) 7,795 Reputation points Microsoft External Staff Moderator
    2025-12-19T02:14:44.4366667+00:00

    Hello @Dani_S ,

    The current approach is okay, but you could also do something like this:

    private static void Main(string[] args)
    {
        Console.OutputEncoding = System.Text.Encoding.UTF8;
        args = EnsureDebugArgs(args);
        Environment.Exit(Run(args));
    }
    
    public static int Run(string[] args)
    {
        // apply license FIRST before doing anything else
        if (!AsposeLicenseManager.ApplyLicense())
        {
            Console.Error.WriteLine("failed to apply aspose license.");
            Console.Error.WriteLine("the program cannot continue without a valid license.");
            return (int)ExitCode.AppError; // <-- RETURN the exit code, don't kill the process
        }
    
        // help flags
        if (args.Length == 0 || args[0] == "help" || args[0] == "--help" || args[0] == "-h")
        {
            ShowHelp();
            return (int)ExitCode.Success;
        }
        if (args[0] == "--help-formats")
        {
            ShowHelpFormats();
            return (int)ExitCode.Success;
        }
    
        // extract the command from the first argument
        string command = args[0].ToLowerInvariant();
    
        try
        {
            switch (command)
            {
                case "gis_convert":
                    return RunGisConverter(args);
                default:
                    Console.WriteLine($"unknown command:  {command}\n");
                    ShowHelp();
                    return (int)ExitCode.AppError;
            }
        }
        catch (Exception ex)
        {
            Console.WriteLine("error:");
            Console.WriteLine(ex.Message);
            return (int)ExitCode.Unexpected;
        }
    }
    

    Happy holidays.

    2 people found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.