Software⏱️ 2 min read📅 2026-06-04

How to Fix: Make sure that the controller has a parameterless public constructor error

Learn how to fix: Make sure that the controller has a parameterless public constructor error.

Quick Answer: Try checking your system settings or restarting.

The controller has a parameterless public constructor error occurs when you add an additional constructor to your DbContext class, preventing it from being resolved by the Web API Dependency Resolver.

This issue is typically caused by adding a new constructor that takes parameters, making it incompatible with the existing dependency resolver.

⚠️ Common Causes

  • To resolve this issue, you need to ensure that any additional constructors added to your DbContext class are parameterless or have default values.
  • Alternatively, you can use the `SetDefaultConstructor` method provided by Entity Framework Core to specify a default constructor for your DbContext class.

🛠️ Step-by-Step Verified Fixes

Specify a parameterless public constructor

  1. Step 1: Remove any additional constructors from your DbContext class that take parameters.
  2. Step 2: Verify that the `SetDefaultConstructor` method is not being used, as it can override the default constructor and cause issues with dependency resolution.

Use the `SetDefaultConstructor` method

  1. Step 1: Use the `SetDefaultConstructor` method to specify a parameterless public constructor for your DbContext class.
  2. Step 2: This will ensure that the Web API Dependency Resolver can resolve instances of your DbContext class correctly.

🎯 Final Words

By following these steps, you should be able to resolve the controller has a parameterless public constructor error and get back to using your modified DbContext class with an additional constructor.

Did this fix your problem?

If not, try searching for specific error codes.

🔍 Search Error Database

❓ Frequently Asked Questions