Skip to content
LatchkeyLatchkey home

WebApplicationFactory "The following constructor parameters did not have matching fixture data" in CI

xUnit could not supply a constructor parameter of your integration test because the class does not implement IClassFixture<T> for that type, or the factory type does not match. Wire the fixture so xUnit injects the WebApplicationFactory.

What this error means

Integration tests fail to run with "The following constructor parameters did not have matching fixture data: WebApplicationFactory<Program> factory" (or your custom factory type).

.NET
The following constructor parameters did not have matching fixture data:
WebApplicationFactory<Program> factory

Diagnose it: SDK version and restore first

Most .NET CI failures are an SDK mismatch or a restore that did not happen. global.json pins the SDK, and if the runner does not have that exact version the failure message is about the project rather than the SDK.

Terminal
dotnet --info
cat global.json 2>/dev/null

# restore explicitly so a restore failure is not reported as a build failure
dotnet restore --verbosity normal
dotnet build --no-restore -warnaserror

Common causes

The test class does not implement IClassFixture

xUnit only injects a fixture the class declares via IClassFixture<T>; without it, the constructor parameter has no source.

The fixture type does not match the parameter

The class declares IClassFixture<WebApplicationFactory<Program>> but the constructor takes a custom factory (or vice versa), so the types do not line up.

How to fix it

Implement IClassFixture with the exact type

  1. Declare IClassFixture<TFactory> on the test class.
  2. Use the same factory type in the class fixture and the constructor parameter.
  3. Reference the app entry type (Program) so the factory can find it.
ApiTests.cs
public class ApiTests : IClassFixture<WebApplicationFactory<Program>>
{
    private readonly WebApplicationFactory<Program> _factory;
    public ApiTests(WebApplicationFactory<Program> factory) => _factory = factory;
}

Expose Program to the test project

For a minimal-hosting Program.cs, make the entry point visible so WebApplicationFactory<Program> compiles.

Program.cs
// end of Program.cs
public partial class Program { }

How to prevent it

  • Match the IClassFixture type to the constructor parameter type.
  • Expose Program (public partial class) for WebApplicationFactory.
  • Share one custom factory type across integration tests.

Frequently asked questions

What causes WebApplicationFactory "The following constructor parameters did not have matching fixture data" in CI?
There are 2 common causes: the test class does not implement iclassfixture and the fixture type does not match the parameter. xUnit only injects a fixture the class declares via IClassFixture<T>; without it, the constructor parameter has no source.
How do I fix WebApplicationFactory "The following constructor parameters did not have matching fixture data" in CI?
There are 2 fixes depending on which cause you have: implement iclassfixture with the exact type and expose program to the test project. Work through them in order, since the first is the most common.
What does WebApplicationFactory "The following constructor parameters did not have matching fixture data" in CI actually mean?
Integration tests fail to run with "The following constructor parameters did not have matching fixture data: WebApplicationFactory<Program> factory" (or your custom factory type).
How do I stop WebApplicationFactory "The following constructor parameters did not have matching fixture data" in CI happening again?
Match the IClassFixture type to the constructor parameter type. The prevention section lists 3 changes that keep it from recurring.

Related guides

References

Not every red build is your code. Latchkey repairs the ones that are not, on the runner. Start free → 30-day trial · No credit card