'What is reason for showing IWindowingPlatform is not registered error?

I am trying to develop an desktop application using Avalonia. In my application the main window is the login form, but actually I don't want to always show the Login form. I keep the user logged in until the user clicks logout.

My app runs fine when I start with the login form, but in other cases (means running the app without showing the login form) it throws IWindowingPlatform is not registered.

Exception thrown: 'System.Exception' in Avalonia.Controls.dll 
An unhandled exception of type 'System.Exception' occurred in Avalonia.Controls.dll 
Could not CreateWindow(): IWindowingPlatform is not registered.

I open the window like this:

    string dir = @"E:\temp\Demo";
    AboutApp about = new AboutApp();
    if (Directory.Exists(dir))
    {
        about.Show();           //throw exception
    }
    else
    {
        BuildAvaloniaApp()
         .StartWithClassicDesktopLifetime(args);
        
       about.Show();
    }

Sample work: https://github.com/Aswathips/DemoWork

Why does it throw the exception and how can I solve it?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source