Skip to main content

How to Resolve Error "CS0132: 'constructor' : a static constructor must be parameterless" in C#

The Compiler Error CS0132 is a structural restriction error. The message reads: " 'ClassName.ClassName(parameters)' : a static constructor must be parameterless".

In C#, a Static Constructor (static ClassName() { ... }) is used to initialize static data or perform actions that need to happen once before the class is used. Because the Common Language Runtime (CLR) calls this constructor automatically (not your code), there is no mechanism for you to pass arguments to it. Therefore, C# forbids parameters in static constructors.

This guide explains the lifecycle of static constructors and how to handle initialization that requires data.

Understanding Static Constructor Lifecycle

Instance constructors are called by you using the new keyword: var obj = new MyClass("argument"); Because you write the call, you can provide arguments.

Static constructors are called by the Runtime (CLR):

  • They run automatically before the first instance is created or any static members are referenced.
  • You never write MyClass.StaticConstructor().
  • Since the Runtime calls it implicitly, it has no way of knowing what arguments you might want to pass.

Therefore, the signature must always be: static ClassName().

Scenario: The Invalid Definition

This error usually occurs when developers treat a static class like a singleton that needs configuration passed into it.

Example: trying to pass a file path or connection string to a static constructor.

public class AppConfig
{
public static string ConfigurationPath;

// ⛔️ Error CS0132: 'AppConfig.AppConfig(string)': a static constructor must be parameterless
// The CLR calls this. It doesn't know what string to pass here.
static AppConfig(string path)
{
ConfigurationPath = path;
}
}

Solution 1: Hardcode or Calculate Internally

If the data needed for initialization is available from the environment (e.g., looking up a config file, reading an Environment Variable, or a constant), remove the parameter and read the data inside the constructor.

using System;

public class AppConfig
{
public static string ConfigurationPath;

// ✅ Correct: No parameters.
static AppConfig()
{
// Logic is self-contained (e.g., reading an Environment Variable)
ConfigurationPath = Environment.GetEnvironmentVariable("APP_CONFIG_PATH")
?? "default.json";
}
}

Solution 2: Use a Static Initialization Method

If you absolutely must pass data from the outside (e.g., from your Main method) to initialize your static class, you cannot use a constructor. Instead, write a standard public static void method.

You simply have to remember to call this method manually at the start of your program.

public class Logger
{
public static string LogFile { get; private set; }

// 1. Standard static constructor (Parameterless)
static Logger()
{
// Set defaults here if needed
LogFile = "default.log";
}

// 2. Manual Initialization Method
// ✅ Correct: Standard methods can accept parameters.
public static void Initialize(string filePath)
{
LogFile = filePath;
}
}

public class Program
{
static void Main()
{
// We must manually call our init method
Logger.Initialize("app.log");
}
}
note

Module Initializers (C# 9.0): C# 9 introduced [ModuleInitializer]. This allows you to write a static method that runs automatically when the assembly loads. However, like static constructors, these methods must be parameterless, so they do not solve the issue of passing external arguments.

Conclusion

CS0132 reminds you that you don't control when or how a static constructor is called.

  1. Remove Parameters: Delete any arguments from static ClassName(...).
  2. Self-Sufficient Logic: If possible, make the constructor find its own data (via files or constants).
  3. Manual Init: If you need to pass arguments, create a public static void Init(...) method and call it manually during application startup.