Unable to cast ProfiledConnection to SqlConnection

730 views
Skip to first unread message

Dan Durland

unread,
Jul 31, 2013, 10:11:35 AM7/31/13
to nhp...@googlegroups.com
I pulled down the latest version of EFProf to evaluate and help troubleshoot a timeout issue on a production box with a WCF service targeting .Net 4.5. Instrumented the code initializing the profiler after initializing the IOC. Everything was working fine and EFProf was profiling as planned starting @ ~2:PM. The app pool was scheduled to recycle @ 11:30PM and @ 11:53PM we started logging out the following error:

System.InvalidCastException: Unable to cast object of type 'HibernatingRhinos.Profiler.Appender.ProfiledDataAccess.ProfiledConnection`1[System.Data.SqlClient.SqlClientFactory]' to type 'System.Data.SqlClient.SqlConnection'.

Once recycled the error disappeared. @ 4:23AM the error reappeared and the app pool was scheduled to recycle @ 4:30AM (No clue on why the scheduling setup this way).
After the recycle the error disappeared again until 7:07AM.

Not a lot to go on and I am unable to repro on my dev box. I have dug through the machine.config and through this group with no real luck. 

Any thoughts or ideas would be appreciated.

Oren Eini (Ayende Rahien)

unread,
Jul 31, 2013, 10:21:53 AM7/31/13
to nhprof
We need a full stack trace to understand what is going on.
Probably you didn't start the profiler as the first thing that happened in your application


--
You received this message because you are subscribed to the Google Groups "nhprof" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nhprof+un...@googlegroups.com.
To post to this group, send email to nhp...@googlegroups.com.
Visit this group at http://groups.google.com/group/nhprof.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Dan Durland

unread,
Jul 31, 2013, 10:22:54 AM7/31/13
to nhp...@googlegroups.com
Sorry wrong group. I will move this to the EFProf group.

Fitzchak Yitzchaki

unread,
Jul 31, 2013, 10:23:29 AM7/31/13
to nhp...@googlegroups.com
Interesting. 

It should not be related to machine.config or anything like that. It's probably an action in your code that take place in a certain time or circumstances?

Please ping us once you can reproduce this.

Hope it helps,

Fitzchak


On Wed, Jul 31, 2013 at 5:11 PM, Dan Durland <daniel...@gmail.com> wrote:

--

Dan Durland

unread,
Jul 31, 2013, 10:32:16 AM7/31/13
to nhp...@googlegroups.com
The profiler is initialized right after the IOC is initialized when the ServiceHostFactory is created. The first hit to the DB is pulling name/value records from a settings table containing 6 rows. This is where it is dying. Could this be related to transient connection issues with the DB server? This is the issue I am trying to ultimately trying to run to ground.


StackTrace:

Exception:Unable to cast object of type 'HibernatingRhinos.Profiler.Appender.ProfiledDataAccess.ProfiledConnection`1[System.Data.SqlClient.SqlClientFactory]' to type 'System.Data.SqlClient.SqlConnection'. Stack:   at System.Data.SqlClient.SqlCommand.set_DbConnection(DbConnection value)
   at System.Data.Common.Utils.CommandHelper.SetStoreProviderCommandState(EntityCommand entityCommand, EntityTransaction entityTransaction, DbCommand storeProviderCommand)
   at System.Data.EntityClient.EntityCommandDefinition.ExecuteStoreCommands(EntityCommand entityCommand, CommandBehavior behavior)
   at System.Data.Objects.Internal.ObjectQueryExecutionPlan.Execute[TResultType](ObjectContext context, ObjectParameterCollection parameterValues)
   at System.Data.Objects.ObjectQuery`1.GetResults(Nullable`1 forMergeOption)
   at System.Data.Objects.ObjectQuery`1.System.Collections.Generic.IEnumerable<T>.GetEnumerator()
   at System.Linq.Enumerable.Single[TSource](IEnumerable`1 source)
   at System.Linq.Queryable.Count[TSource](IQueryable`1 source)
   at System.Data.Entity.Migrations.History.HistoryRepository.Exists(HistoryContext context)
   at System.Data.Entity.Migrations.History.HistoryRepository.GetLastModel(String& migrationId)
   at System.Data.Entity.Migrations.History.HistoryRepository.GetLastModel()
   at System.Data.Entity.Internal.ModelCompatibilityChecker.CompatibleWithModel(InternalContext internalContext, ModelHashCalculator modelHashCalculator, Boolean throwIfNoMetadata)
   at System.Data.Entity.CreateDatabaseIfNotExists`1.InitializeDatabase(TContext context)
   at System.Data.Entity.Internal.InternalContext.PerformInitializationAction(Action action)
   at System.Data.Entity.Internal.InternalContext.PerformDatabaseInitialization()
   at System.Data.Entity.Internal.RetryAction`1.PerformAction(TInput input)
   at System.Data.Entity.Internal.LazyInternalContext.InitializeDatabaseAction(Action`1 action)
   at System.Data.Entity.Internal.InternalContext.GetEntitySetAndBaseTypeForType(Type entityType)
   at System.Data.Entity.Internal.Linq.InternalSet`1.Initialize()
   at System.Data.Entity.Internal.Linq.InternalSet`1.GetEnumerator()
   at ARI.Catalog.AUS.WebServices.WebServiceSettings.Hydrate() in d:\SourceCode\ARIUpdateService\src\ARI.Catalog.AUS.WebServices\WebServiceSettings.cs:line 102
   at ARI.Catalog.AUS.WebServices.WebServiceSettings.GetSetting[T](String name, T& value) in d:\SourceCode\ARIUpdateService\src\ARI.Catalog.AUS.WebServices\WebServiceSettings.cs:line 85
   at ARI.Catalog.AUS.WebServices.WebServiceSettings.GetSetting[T](String name, T defaultValue) in d:\SourceCode\ARIUpdateService\src\ARI.Catalog.AUS.WebServices\WebServiceSettings.cs:line 76
   at ARI.Catalog.AUS.WebServices.Wcf.AUSService_V2.GetUpdates(UpdateRequestDTO_V2 request) in d:\SourceCode\ARIUpdateService\src\ARI.Catalog.AUS.WebServices\Soap\AgentService\AUSService_V2.cs:line 128 


On Wednesday, July 31, 2013 8:11:35 AM UTC-6, Dan Durland wrote:

Oren Eini (Ayende Rahien)

unread,
Jul 31, 2013, 10:33:57 AM7/31/13
to nhprof
Please do it as the _very first thing_, that should help


--

Dan Durland

unread,
Jul 31, 2013, 10:50:31 AM7/31/13
to nhp...@googlegroups.com
Initializing the profiler before the IOC was a no-op on the production server because the profiler was throwing an exception in SetupDatabaseDefaultConnectionFactoryIfNeeded trying to locate System.Data.Entity.dll before the current domain had loaded it up. The server does not have the Reference Assemblies directory for 4.x as VS is not installed. 

Out of curiosity any idea on why it would profile fine for hours then die related to where the profiler is initialized?

Thanks for the fast replies!

Oren Eini (Ayende Rahien)

unread,
Jul 31, 2013, 11:11:15 AM7/31/13
to nhprof
I am not really sure, we usually see this if you used EF before using EF Prof
Reply all
Reply to author
Forward
0 new messages