Using EFProf and MiniProfiler simultaneously in an ASP.NET MVC 5.1, Entity Framework 5 Code-First Project
Posted January 23, 2014
Reading time: 2 minutes
We’re already using the excellent Entity Framework Profiler (EFProf) to gauge EF performance in our application. However, we wanted more information about the overall application performance, and thus turned to MiniProfiler.
Installing MiniProfiler was easy enough, but upon running the application, I got an error:
|
|
Hmm. That’s weird. So I commented out my EFProf initialization code:
|
|
And MiniProfiler worked fine.
I then wrote a test application to try to isolate the problem, and got a different error:
|
|
It turns out that MiniProfiler expects its DbCommand to implement ICloneable:
|
|
Unfortunately, dotPeek reveals that EFProf’s ProfiledCommand does not implement ICloneable:
|
|
Fortunately, there is a workaround: initialize MiniProfiler before initializing EFProf. Or, in source code form, do this in Global.asax:
|
|
Instead of this:
|
|
And EFProf and MiniProfiler will coexist happily together.
(Note that this means EFProf initialization happens in Global.asax instead of in PreApplicationStartMethod installed by the EFProf NuGet package.)
Version information:
- ASP.NET MVC 5.1.0
- Entity Framework 5.0.0
- EFProf Build 2225
- MiniProfiler 2.1.0