Compiler error · error CS1729
'X' does not contain a constructor that takes N arguments
Your new X(…) call doesn't match any constructor the class declares. Nine times out of ten the cause is the same: the moment you write ANY constructor, C# stops providing the free empty one — and old new X() calls break.
See it happen
class Person
{
public Person(string name)
{
Console.WriteLine("created " + name);
}
}
Person p = new Person(); // CS1729: only a (string) constructor exists now
Fix 1: pass what the constructor wants
class Person
{
public Person(string name)
{
Console.WriteLine("created " + name);
}
}
Person p = new Person("Ada");
Fix 2: add back the empty constructor
If new Person() is genuinely valid — object initializers will fill the data — declare a parameterless constructor alongside:
class Person
{
public string Name { get; set; }
public Person() { } // explicit empty ctor
public Person(string name) { Name = name; }
}
Person p = new Person { Name = "Ada" }; // works again
Console.WriteLine(p.Name);
Why C# works this way
The free empty constructor is a convenience for classes with no setup needs. When you declare Person(string name), you're saying "a Person is not valid without a name" — so C# helpfully removes the constructor that would create an invalid one. The error is the language enforcing your own rule.
Constructors overload like methods (same rules, CS1501/CS7036 family) — and in inheritance, the child's constructor must hand the parent its arguments via : base(…):
class Student : Person
{
public Student(string name, int grade) : base(name) // feed the parent
{
// ...
}
}
Frequently asked
What does error CS1729 mean in C#?
The empty constructor only exists while the class declares none. Once you write Person(string name), C# assumes a Person is not valid without a name and stops providing new Person() — re-add an explicit public Person() { } if it should stay legal.
Why did new X() stop working after I added a constructor?
undefined
Checklist
- Read the constructor's parameter list; your call's count must match one of them exactly.
- Declared any constructor? The empty one is gone — re-add it explicitly if
new X()should stay legal. - Object initializers (
new X { … }) don't replace constructor arguments — they set properties after. - Inheriting? Route required arguments to the parent with
: base(…).