Search code examples
.netexceptionlabview

Why is killing an Console.Clear() in a .NET Application my LabView call?


I got a strange behavior in my Labview 8.2 program. I wrote a console application in C# because this horrible old labview is not capable of .NET DLLs.

However - I have a Console.Clear() command in my application that should clear the screen. This works in standalone perfectly.

But if I try to open my exe from within labview using the exec sys command vi, it will crash with an unmanaged handler. The exception is thrown by the CLI.

What the heck does labview do here? Why is it not simply showing the command promt starting the application but doing something not understandable and crashing?

Does this mean I cannot open ANY command line tool that's using Console.Clear() within it source code?

Exception + Stack Trace

Unhandled exception: System.IO.IOException: The handle is invalid.

    at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
    at System.Console.GetBufferInfo(Boolean throwOnNoConsole, Boolean& succeeded)
    at System.Console.Clear()
    at TestApp.Program.Main(String[] args) in C:\Users\xxxx\Documents\Visual Studio 2015\Projects\xxx\TestApp\Program.cs:Zeile 14.

Labview code


Solution

  • If you want to keep the Console.Clear() in your code but want it to work in a system where no console window is displayed then you will need to determine if the console has been displayed.

    var output = Console.OpenStandardInput();
    
    if (output != System.IO.Stream.Null)
        Console.Clear();