Consolonia icon indicating copy to clipboard operation
Consolonia copied to clipboard

Startup error: "Invalid controller"

Open SuperJMN opened this issue 3 years ago • 2 comments

Repro steps:

  1. Create project with default Avalonia MVVM template
  2. Modify Program.cs
    internal class Program
    {
        // Initialization code. Don't use any Avalonia, third-party APIs or any
        // SynchronizationContext-reliant code before AppMain is called: things aren't initialized
        // yet and stuff might break.
        [STAThread]
        public static void Main(string[] args)
        {
            TaskScheduler.UnobservedTaskException += (_, args) =>
            {
                Environment.FailFast("Exception in unobserved task",
                    new InvalidOperationException("Exception happened in unobserved Task (case 2)",
                        args.Exception));
            };

            //todo: setup error handler
            AppBuilder.Configure<App>()
                .UseConsolonia()
                .UseAutoDetectedConsole()
                .LogToException()
                .StartWithConsoleLifetime(Array.Empty<string>());
        }
    }
  1. Modified App.cs
    public partial class App : Application
    {
        public override void Initialize()
        {
            AvaloniaXamlLoader.Load(this);
        }

        public App()
        {
            var baseUri = new Uri($"avares://{typeof(App).Namespace}");
            Styles.Add(new TurboVisionDarkTheme(baseUri));
        }

        public override void OnFrameworkInitializationCompleted()
        {
            ((IClassicDesktopStyleApplicationLifetime) ApplicationLifetime).MainWindow = new MainWindow();
            base.OnFrameworkInitializationCompleted();
        }
    }
  1. Run the app.
  2. This exception is thrown:

image

System.IO.IOException: 'Invalid controller.'

Stack Trace:

at System.ConsolePal.set_CursorVisible(Boolean value) at Consolonia.PlatformSupport.Win32Console..ctor() at Consolonia.PlatformSupport.PlatformSupportExtensions.UseAutoDetectedConsole[TAppBuilder](TAppBuilder builder) at AvaloniaApplication4.Program.Main(String[] args) in E:\Repos\AvaloniaApplication4\AvaloniaApplication4\Program.cs:line 26

Installed Packages

 <ItemGroup>
    <PackageReference Include="Avalonia" Version="0.10.18" />
    <PackageReference Include="Avalonia.Desktop" Version="0.10.18" />
    <!--Condition below is needed to remove Avalonia.Diagnostics package from build output in Release configuration.-->
    <PackageReference Condition="'$(Configuration)' == 'Debug'" Include="Avalonia.Diagnostics" Version="0.10.18" />
    <PackageReference Include="Avalonia.ReactiveUI" Version="0.10.18" />
    <PackageReference Include="Consolonia.PlatformSupport" Version="0.10.18-alpha-134" />
    <PackageReference Include="Consolonia.Themes.TurboVision" Version="0.10.18-alpha-134" />
    <PackageReference Include="XamlNameReferenceGenerator" Version="1.3.4" />
  </ItemGroup>

SuperJMN avatar Nov 18 '22 11:11 SuperJMN

Thank you for details! May I ask which terminal are you running it in? Default CMD on Windows?

jinek avatar Nov 19 '22 16:11 jinek

@SuperJMN I probably found the solution. You have to manually change output type from WinExe to Exe at your csproj file. image

Same error can happen if running in unsupported terminals or output or input are redirected. Some similar issues: https://github.com/Mpdreamz/shellprogressbar/issues/22 https://github.com/dotnet/runtime/issues/28625#issuecomment-460736213

jinek avatar Nov 19 '22 16:11 jinek

I will close this one, it's just matter to set the output type. We will introduce project template with correct type within this task https://github.com/jinek/Consolonia/issues/11

jinek avatar Nov 02 '24 11:11 jinek