May 06

Error making asyn call in Entity Framework: There is already an open DataReader associated with this Command which must be closed first

Using Entity Framework 6.0 I got this message. This problem occurs when mostly in Async environment. This is due to a reader (in the same DBContext) that is still open, while another reader tries to open an new one. Typically this is a async issue.

In my MVC 5 app I have a Async call to my webapi. My problem was that I created a second repository object in a method, while the first repository was created by Unity Dependency Injection Framework was not finished reading.

My solution:

In stead of newing the repository up in the method I injected it in the constructor and all issues where solved.

A better solution:

Add MultipleActiveResultSets=True to the connectionstring of the database.

Apr 11

Entity Framework is returning old data when using Webapi

Strange thing today. I have a MVC 5 webapp, that has Webapi capabilities used. Problem is that I get old data when retrieving it from a Webapi controller, but fresh data when retrieving directly from the database.

The issue was in the user of automapper. I had automapper map a datetime taking the timezone in account. I had to search in the database to get the right timezone. There the old value was presented. Probably due to Dependency Injection, there was a different databasecontext loaded, that did not see changes made.

Solution: quit using automapper and map the properties manual in my own Mapper class.

Jan 30

Build fails (of test project) but no errors are reported in the Visual Studio 2012 Build Output window after nuget package update

After updating my nuget packages my build of the test project was failing, without any error reported in the build output window.

First of all you can turn on verbose logging:

  • Tools
  • Options
  • Project and Solutions
  • Build and Run
  • Set these to options to Diagnostic:
    • MSBuild project build output verbosity
    • MSBuild project build log file verbosity

Probably you’ll see the error appearing in you build log file of in the build output file.

In my case the System.web.mvc reference was updated, but the fake assembly that I had generated was not updated and one assembly was missing.