mono/mono · error

%s

Error message

%s

What it means

mono_trace_set_options() (trace.c:55) parses a call specification string for method tracing via mono_callspec_parse() (callspec.c:312). If parsing fails, it prints the error string returned by the parser and returns NULL — it does NOT call exit(1). The callspec grammar accepts tokens: 'M:' (method descriptor), 'N:' (namespace), 'T:' (class), 'E:' (exception type), bare assembly names, and keywords 'all', 'program', 'wrapper', 'disabled', joined by commas; a leading '-' excludes. Parser error messages include 'Syntax error at or around ...', 'Invalid method name: ...', 'Expecting an expression', and 'Syntax error in method specification'. This variable is typically set via the --trace= command-line option or the MONO_TRACE environment variable.

Source

Thrown at mono/mini/trace.c:59

static MonoCallSpec trace_spec;

static volatile gint32 output_lock = 0;

gboolean mono_trace_eval_exception (MonoClass *klass)
{
	return mono_callspec_eval_exception (klass, &trace_spec);
}

gboolean mono_trace_eval (MonoMethod *method)
{
	return mono_callspec_eval (method, &trace_spec);
}

MonoCallSpec *mono_trace_set_options (const char *options)
{
	char *errstr;
	if (!mono_callspec_parse (options, &trace_spec, &errstr)) {
		fprintf (stderr, "%s\n", errstr);
		g_free (errstr);
		return NULL;
	}

	return &trace_spec;
}

static
#ifdef MONO_KEYWORD_THREAD
MONO_KEYWORD_THREAD
#endif
int indent_level = 0;
static guint64 start_time = 0;

static double seconds_since_start (void)
{
	guint64 diff = mono_100ns_ticks () - start_time;
	return diff/10000000.0;

View on GitHub (pinned to 0f53e9e151)

Solutions

  1. Prefix method specs with 'M:' and use valid method-descriptor syntax, e.g. `--trace=M:MyNamespace.MyClass.MyMethod`.
  2. Use 'T:Namespace.ClassName' to trace all methods of a class, 'N:Namespace' for a namespace, or 'all' to trace everything.
  3. Separate multiple specs with commas and prefix a spec with '-' to exclude it, e.g. `--trace=all,-M:System.*`.

Example fix

# before
mono --trace="MyClass.MyMethod" app.exe

# after
mono --trace="M:MyNamespace.MyClass.MyMethod" app.exe
Defensive patterns

Strategy: validation

Validate before calling

# Validate the callspec format before passing to --trace
# Valid prefixes: M: T: N: E: ; keywords: all program wrapper disabled ; '-' to exclude
validate_callspec() {
  local spec="$1"
  IFS=',' read -ra parts <<< "$spec"
  for part in "${parts[@]}"; do
    local stripped=${part#+}  # remove leading +
    stripped=${stripped#-}    # remove leading -
    case "$stripped" in
      M:*|T:*|N:*|E:*) continue ;;
      all|program|wrapper|disabled) continue ;;
      *) echo "Invalid callspec token: '$part'" >&2; return 1 ;;
    esac
  done
}
validate_callspec "$TRACE_SPEC" && mono --trace="$TRACE_SPEC" app.exe

Prevention

When it happens

Trigger: Passing a malformed callspec to mono --trace (e.g. `mono --trace=M:Foo.Bar(` with unbalanced parens, or `--trace=X:BadPrefix` using an unrecognized prefix); forgetting the 'M:'/'T:'/'N:'/'E:' prefix and supplying a raw method signature that the parser interprets as an assembly name; using characters outside the allowed filename-char set (A-Z, a-z, 0-9, '.', ':', '_', '-', '`').

Common situations: Trying to trace a specific method for debugging and getting the callspec syntax wrong; following incomplete documentation about the --trace flag format; passing a C# fully-qualified name without the required prefix token.

Related errors


AI-assisted analysis of mono/mono@0f53e9e151 (2026-08-13). Data as JSON: /api/errors/c76d650607995865. Report an issue: GitHub.