Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Logger creation fails when there is no terminal #282

Open
katjoek opened this issue Oct 28, 2022 · 1 comment
Open

Logger creation fails when there is no terminal #282

katjoek opened this issue Oct 28, 2022 · 1 comment

Comments

@katjoek
Copy link

katjoek commented Oct 28, 2022

Describe the bug
I've created a webserver using EmbedIO. That webserver is to be started by another application without the user seeing that it is running. So no console window should be present. I'm starting the application using this process definition:

        return new Process
        {
            EnableRaisingEvents = true,
            StartInfo = new ProcessStartInfo
            {
                WorkingDirectory = workingDirectory,
                FileName = fileName,
                CreateNoWindow = true,
                UseShellExecute = false,
                RedirectStandardInput = true,
                RedirectStandardOutput = true,
            },
        };

When the webserver application is started, the application fails. In the EventViewer we see this:

Framework Version: v4.0.30319
Description: The process was terminated due to an unhandled exception.
Exception Info: System.IO.IOException
   at System.IO.__Error.WinIOError(Int32, System.String)
   at System.Console.set_CursorVisible(Boolean)
   at Swan.Terminal..cctor()

Exception Info: System.TypeInitializationException
   at Swan.Terminal.get_IsConsolePresent()
   at Swan.Logging.Logger..cctor()

Exception Info: System.TypeInitializationException
   at Swan.Logging.Logger.Info(System.String, System.String, System.Object, System.String, System.String, Int32)
   at EmbedIO.WebServer.CreateHttpListener()
   at EmbedIO.WebServer..ctor(System.Action`1<EmbedIO.WebServerOptions>)
   at Luxexcel.LensRecognition.Server.Program.CreateWebServer(System.String)
   at Luxexcel.LensRecognition.Server.Program.RunWebserver(Luxexcel.LensDiscovery.Shared.CommandLineOptions)
   at CommandLine.ParserResultExtensions.WithParsed[[System.__Canon, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]](CommandLine.ParserResult`1<System.__Canon>, System.Action`1<System.__Canon>)
   at Luxexcel.LensRecognition.Server.Program.Main(System.String[])

It fails in Logger's class constructor on IsConsolePresent.

I'm using Swan 3.1.0

Expected behavior
It should not throw an exception and not try to add the terminal as a sink when it isn't there.

Desktop (please complete the following information):

  • OS: Windows 10
  • .NET Framework 4.8
@rdeago
Copy link
Collaborator

rdeago commented Oct 28, 2022

Hello @katjoek, thanks for using EmbedIO! Oh, and Swan, of course.

Unfortunately the bug is in Terminal's class initializer, where it checks for the existence of the console. I'm sure the irony doesn't escape you.

The only workaround I can think of is to replace this line:

                CreateNoWindow = true,

with this:

                WindowStyle = ProcessWindowStyle.Hidden,

so the console is created but doesn't clutter your screen. I'm not 100% sure it will work but I'd give it a shot.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants