Ok, so I figured out a workaround. I do not particularly like it but, it works and appears to have no ill side effects.
I definitely doubt it was related to Simple Injector, but will post here if it is of any benefit to others.
The basic structure of my app is quite straight forward using:
- Unit Of Work
- An Entity Base class that is generically typed and handles all my Entity related reusable code (paging, searching, etc)
I have two projects that I am testing. 1)
Is a Web Api 2.0 using Owin
a test project for integration tests (think: testing custom authentication, handlers, ect)
So everything works fine when deployed to IIS. However when I was running it in my test project it was failing when setting a property in my Entity Base class
_entity = DbContext.Set<TBaseEntity>();
As you can see from the errors in my post above they point to either a configuration (app.config, dll version mismatch, or reference issue) or when looking at the inner exception it looks like a type is not scoped correctly or not accessible for some reason.
Through sheer trial and error I followed this back up the chain to where my UOW was accessing my DbContext. I found the same error buried in the Database.Configuration property of the DbContext, even though it was not throwing the error until I tried to assign
my DbSet property. Again, mind you if I set a breakpoint ANYWHERE between where I was assigning my property or where I was passing my DbContext to my UOW it all worked as expected with no errors.
Remove the breakpoint and it failed.
What has resolved the issue is calling DbContext.Database.Initialize() after setting the context on my UOW. Since this is a Database first project I don't see why it would need it and am baffled as to why adding a breakpoint would resolve it. My best guess
is that the breakpoint is allowing EntityFramework time or resources to do this initialization internally.
I hate to add code just for the sake of resolving some ridiculous error. If anyone has any thoughts it would set my mind at ease but, it is working so I suppose I can live with it.