I’ve encountered a similar problem to the one raised here: http://code.google.com/p/mvc-mini-profiler/issues/detail?id=125 that was unable to be reproduced re compiled linq2sql queries.
System.InvalidCastException: Unable to cast object of type 'StackExchange.Profiling.Data.ProfiledDbDataReader' to type 'System.Data.SqlClient.SqlDataReader'.
The specific scenario which seems to cause this for me:
- run ASP.NET MVC solution with the profiling disabled - I have this as an option against a user account so different users can toggle on/off the profiling. When disabled, a normal SqlConnection is used.
- hit the page that uses the compiled query - all OK
- enable the profiling functionality (toggle the user account level flag) so that db connections are now wrapped in a ProfiledDbConnection
- revisit the page that uses the compiled query = error