Skip to content

PostSharp crashes with TypeInitializationException when PostSharpTrace="*" is used with PostSharpUsePipeServer=False #18

@gfraiteur

Description

@gfraiteur

Description

When using PostSharpTrace="*" (wildcard) together with PostSharpUsePipeServer=False, PostSharp crashes with a TypeInitializationException in CommonTrace..cctor().

The crash has two contributing factors:

  1. The * wildcard is not recognized as a valid trace category by the PostSharp command-line parser. When PostSharpUsePipeServer=False, the MSBuild task passes /T:* on the command line, which the standalone postsharp-x64.exe rejects:
    POSTSHARP : error : Cannot parse the argument {/T:*} at position {20} from command line.

  2. The error-handling code path triggers a static constructor (CommonTrace..cctor()) that calls BuildTimeLogger.GetInstance() before BuildTimeLogger.Initialize() has been called, causing a cascading TypeInitializationException:
    System.TypeInitializationException: The type initializer for "PostSharp.CommonTrace" threw an exception. ---> System.InvalidOperationException: Cannot call IsEnabled because Initialize has not been called. at PostSharp.Extensibility.BuildTimeLogging.BuildTimeLoggingConfiguration.IsEnabled(String category) at PostSharp.Extensibility.BuildTimeLogging.BuildTimeLogger.GetInstance(String category) at PostSharp.CommonTrace..cctor()

The process exits with code 12.

Expected Behavior

Either:

  • PostSharpTrace="*" should be supported as a wildcard to enable all trace categories, OR
  • An invalid trace category should produce a clear error message without crashing

In both cases, the error-handling code path should not access BuildTimeLogger before it has been initialized.

Workaround

Use a specific trace category name instead of the wildcard:
msbuild -p:PostSharpTrace="Licensing" -p:PostSharpUsePipeServer=False ...

Environment

  • PostSharp 2025.1.2
  • .NET Framework 4.8.1
  • PostSharpUsePipeServer=False (non-pipe-server mode)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions