This project is read-only.

No error with a breakpoint. Take breakpoint away and I get an error, Any ideas.

Jan 13, 2015 at 5:56 AM
I am using SimpleInjector in a WebApi 2.0 project. Everything works fine when deployed to IIS. However when I run some integration tests I am getting errors when trying to assign a property to DbContext.Set<TBaseEntity>();

However, If I set a breakpoint after the line that sets the property everything works. Remove the breakpoint and I get an error.
  • Tried setting a Thread.Sleep, no go.
  • Tried changing the Lifestyle scope of the DbContext and the generically typed base class where the error occurs, no go.
  • Tried moving the composition of the DI container registrations, no go.
  • Made sure the config in the Web Api project and Test project had the same assemblies and EntityFramework configurations.
  • Cleared out my bin directories.
  • Restarted Visual Studio
  • Restarted the machine.
Error info:
[System.Configuration.ConfigurationErrorsException] = {"Configuration system failed to initialize"}

_innerException = {"Type is not resolved for member 'Namespace.Common.Errors.ErrorType,Namespace.Common, Version=, Culture=neutral, PublicKeyToken=null'."}

I have searched high and low for 2 days.

Any help would be greatly appreciated.
Jan 13, 2015 at 6:26 AM
Can you post the required code to reproduce this issue and a complete stack trace? Can you describe why you think this is related to Simple Injector? Thanks.
Jan 13, 2015 at 5:05 PM
I can't say that it is directly related to Simple Injector. I have just banged my head against this issue for so long, I am looking for answers anywhere.

Since the full code to reproduce is so large I will have to isolate and attempt to recreate it in a separate sample project. I will get started on that.
Jan 13, 2015 at 8:32 PM
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
  • Repositories
  • 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 2) 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.

Jan 14, 2015 at 8:56 AM
A typical case of a Heisenbug. Perhaps you even hit a concurrency bug in Entity Framework.