---
title: FAQ
description: Answers to questions people actually ask about AutoFixture.
---

## Why does `Create` throw `ObjectCreationException`?

AutoFixture could not finish the object graph. The exception (often `ObjectCreationExceptionWithPath`) usually means one of these:

| Cause | What to do |
| --- | --- |
| Interface or abstract type | Add [AutoMoq](/docs/integrations/automoq), [AutoNSubstitute](/docs/integrations/autonsubstitute), or [AutoFakeItEasy](/docs/integrations/autofakeiteasy) — or [`Register`](/docs/how-to/register-freeze-inject) a concrete type |
| Circular reference | Replace the default recursion behavior — see [below](#how-do-i-deal-with-circular-references) |
| Property / constructor AutoFixture cannot satisfy | Use [Build DSL](/docs/fundamentals/build-dsl) (`With` / `Without` / `Do`) or a [customization](/docs/fundamentals/customizations) |

Read the request path in the exception — it shows which type failed.

## What’s the difference between `Freeze`, `Inject`, and `Register`?

All three change how later requests for a type are resolved:

| Method | Meaning |
| --- | --- |
| `Freeze<T>()` | AutoFixture **creates** `T` once, then reuses that instance |
| `Inject(instance)` | You **supply** the instance; every request gets that same object |
| `Register(() => …)` | You supply a **factory**; AutoFixture calls it for each request |

```csharp
var frozen = fixture.Freeze<ClientDto>();          // AF creates, then reuses
fixture.Inject(new ClientDto { Name = "x" });      // you own the instance
fixture.Register(() => DateTime.UtcNow.Date);      // factory each time
```

→ [Register, Freeze, and Inject](/docs/how-to/register-freeze-inject)

## How do I deal with circular references?

By default AutoFixture **throws** when it detects a loop (for example `Session` → `Language` → `Sessions`). That is intentional.

To omit the recursive property instead:

```csharp
fixture.Behaviors
    .OfType<ThrowingRecursionBehavior>()
    .ToList()
    .ForEach(b => fixture.Behaviors.Remove(b));
fixture.Behaviors.Add(new OmitOnRecursionBehavior());
```

For a single object, `Build` + `Without` can skip the back-reference without changing fixture-wide behavior.

→ [Circular references](/docs/how-to/circular-refs)

## Why can’t AutoFixture create my interface?

AutoFixture builds **concrete** types. It does not invent implementations for interfaces or abstract classes.

```csharp
fixture.Customize(new AutoMoqCustomization());
var service = fixture.Create<OrderService>(); // IOrderRepository becomes a Moq mock
```

Use the same idea with NSubstitute or FakeItEasy. For `[AutoData]`, put the customization in a [custom AutoData attribute](#how-do-i-share-fixture-setup-across-many-tests).

→ [Integrations overview](/docs/integrations)

## How do I get mocks into `[AutoData]` parameters?

Plain `[AutoData]` has no mocking. Subclass `AutoDataAttribute` so the fixture includes AutoMoq (or another library), then freeze the mock (or the interface):

```csharp
public class AutoMoqDataAttribute : AutoDataAttribute
{
    public AutoMoqDataAttribute()
        : base(() => new Fixture().Customize(new AutoMoqCustomization()))
    {
    }
}

[Theory, AutoMoqData]
public void Test(
    [Frozen] Mock<IOrderRepository> repository,
    OrderService sut,
    Order order)
{
    sut.PlaceOrder(order);
    repository.Verify(r => r.Save(order), Times.Once);
}
```

→ [xUnit.net 3 — custom AutoData](/docs/integrations/xunit3#custom-autodata-attribute) · [AutoMoq](/docs/integrations/automoq)

## How do I share fixture setup across many tests?

Don’t repeat `new Fixture().Customize(...)` in every test. One custom AutoData attribute holds your team conventions (auto-mocking, recursion behavior, date factories, …):

```csharp
public class DefaultAutoDataAttribute : AutoDataAttribute
{
    public DefaultAutoDataAttribute()
        : base(() => new Fixture()
            .Customize(new AutoMoqCustomization { ConfigureMembers = true }))
    {
    }
}
```

Use `[DefaultAutoData]` (and a matching InlineAutoData subclass) on theories.

→ [Custom AutoData attribute](/docs/integrations/xunit3#custom-autodata-attribute)

## I froze an interface — why isn’t my SUT using it?

Freezing works when the SUT requests the **same type** you froze (or a matching type with `[Frozen(Matching…)]`). Library differences:

- **Moq** — prefer `Freeze<Mock<IOrderRepository>>()`. Freezing the interface freezes `mock.Object`; use `Mock.Get(repo)` if you need `Verify`. See [AutoMoq wrappers](/docs/integrations/automoq#mock-wrappers-and-interface-requests).
- **NSubstitute / FakeItEasy** — freeze the **interface** (there is no `Mock<T>` wrapper). That instance is what the SUT receives.

With `[Frozen]` on AutoData, parameter **order** matters: freeze first, then create the SUT. For a concrete type that should satisfy an interface constructor parameter, use `[Frozen(Matching.ImplementedInterfaces)]`.

→ [Frozen](/docs/integrations/xunit3#frozen)

## How do I fill a get-only / read-only collection?

`With` needs a writable property. For a list exposed with a private setter (or get-only `IList<T>` filled in the constructor), mutate after create:

```csharp
var order = fixture.Build<Order>()
    .Do(o => fixture.AddManyTo(o.OrderLines))
    .Create();
```

→ [Collections](/docs/how-to/collections)

## I’m on AutoFixture 4 — what changes in v5?

Pin **matching** v5 packages together. Test integrations move to **AutoFixture.Xunit3** / **AutoFixture.NUnit4** and target **.NET 8+**. Core APIs (`Fixture`, `Create`, `Build`, `Customize`) stay familiar.

→ [v4 to v5 migration](/docs/reference/v4-to-v5-migration)

## Is AutoFixture a DI container? Can I use it in production?

**No.** AutoFixture generates anonymous test data. It is not an application composition root and is not meant for production runtime.

For tests that need interfaces, pair it with a mocking library ([AutoMoq](/docs/integrations/automoq), and so on) — still only in the test project.

## Generated values are noisy in failure messages — can I make them readable?

Use **AutoFixture.SeedExtensions** for prefixed strings, or customize how a type is created:

```csharp
var name = fixture.Create("Customer"); // e.g. "Customer3f2a…"
fixture.Customize<int>(c => c.FromSeed(seed => seed)); // stable ints when seeded
```

→ [Seed extensions](/docs/extensions/seed-extensions)
