2

When I trying to launch this application:

private static void Main(string[] args)
{
    Console.ForegroundColor = ConsoleColor.Cyan;
    Console.WriteLine("test");
}

under mono, it fails with this exception:

Unhandled Exception:
System.ArgumentNullException: Argument cannot be null.
Parameter name: format
  at System.ParameterizedStrings.Evaluate (System.String format, FormatParam[] args) [0x00000] in <filename unknown>:0
  at System.TermInfoDriver.ChangeColor (System.String format, ConsoleColor color) [0x00000] in <filename unknown>:0
  at System.TermInfoDriver.set_ForegroundColor (ConsoleColor value) [0x00000] in <filename unknown>:0
  at System.ConsoleDriver.set_ForegroundColor (ConsoleColor value) [0x00000] in <filename unknown>:0
  at System.Console.set_ForegroundColor (ConsoleColor value) [0x00000] in <filename unknown>:0
  at FudpLoader.Application.Program.Main (System.String[] args) [0x00000] in <filename unknown>:0
[ERROR] FATAL UNHANDLED EXCEPTION: System.ArgumentNullException: Argument cannot be null.
Parameter name: format
  at System.ParameterizedStrings.Evaluate (System.String format, FormatParam[] args) [0x00000] in <filename unknown>:0
  at System.TermInfoDriver.ChangeColor (System.String format, ConsoleColor color) [0x00000] in <filename unknown>:0
  at System.TermInfoDriver.set_ForegroundColor (ConsoleColor value) [0x00000] in <filename unknown>:0
  at System.ConsoleDriver.set_ForegroundColor (ConsoleColor value) [0x00000] in <filename unknown>:0
  at System.Console.set_ForegroundColor (ConsoleColor value) [0x00000] in <filename unknown>:0
  at FudpLoader.Application.Program.Main (System.String[] args) [0x00000] in <filename unknown>:0

Version of Mono is:

Mono JIT compiler version 4.0.2 (Stable 4.0.2.5/c99aa0c Чт. сент. 17 16:22:45 MSK 2015)
Copyright (C) 2002-2014 Novell, Inc, Xamarin Inc and Contributors. www.mono-project.com
        TLS:           __thread
        SIGSEGV:       normal
        Notifications: epoll
        Architecture:  armel,vfp+hard
        Disabled:      aot,profiler,debug
        Misc:          softdebug
        LLVM:          supported, not enabled.
        GC:            sgen

Launching in Linux, builded with BuildRoot and running on ARM processor. If I not trying to chane console's color, application works fine; if I launch it on Linux on virtual machine, colored application works fine too.

Paboka
  • 422
  • 1
  • 5
  • 15

2 Answers2

4

I needed to set the environment variable TERM, TermInfo began to work properly. In my case, it was:

export TERM=xterm-color
Paboka
  • 422
  • 1
  • 5
  • 15
1

If follow your exception stacktrace with mono sources, you can see that mono uses TermInfo to get capabilities of current terminal. When setting foreground color it queries for SetAForeground capability, and your error happens when it fails. So, terminfo tells mono that SetAForeground capability is not supported by current terminal.

Evk
  • 98,527
  • 8
  • 141
  • 191