Collection fixture won't inject

This was a silly error and it took me a bit to figure out why it wasn't working:

[CollectionDefinition] goes on the collection definition class, but [Collection] goes on the test class. I was on autopilot and didn't notice this.

You'll also get this if you have multiple [CollectionDefinition] attributes with the same name on different classes. Just use one!


In my case, the fixture and collection were in a shared testing assembly. I found that XUnit DI could not find it. So, I had to define a fixture that inherited those classes in the shared assembly to both share the functionality while getting it to register in my test classes.


This can also happen if your Collection's constructor throws an error. You may need to debug that code by alternative means, since the error message provided by xUnit isn't helpful in this case.