dotnet: EF6.2 "Value cannot be null. Parameter name: connection"

I’m using MiniProfiler.EF6 4.0.0-alpha9-00215, which is the latest version available on MyGet right now.

After calling MiniProfilerEF6.Initialize(), the following exception is thrown when querying the database:

Value cannot be null. Parameter name: connection
   at System.Data.Entity.Utilities.Check.NotNull[T](T value, String parameterName)
   at System.Data.Entity.Infrastructure.DefaultDbProviderFactoryResolver.ResolveProviderFactory(DbConnection connection)
   at StackExchange.Profiling.EntityFramework6.EFProfiledDbProviderFactoryResolver.ResolveProviderFactory(DbConnection connection) in C:\projects\dotnet\src\MiniProfiler.EF6\EFProfiledDbProviderFactoryResolver.cs:line 28
   at System.Data.Entity.Utilities.DbConnectionExtensions.GetProviderFactory(DbConnection connection)
   at System.Data.Entity.Core.Common.DbProviderServices.GetProviderFactory(DbConnection connection)
   at System.Data.Entity.Migrations.DbMigrator.CreateConnection()
   at System.Data.Entity.Migrations.DbMigrator.EnsureDatabaseExists(Action mustSucceedToKeepDatabase)
   at System.Data.Entity.Migrations.DbMigrator.Update(String targetMigration)
   at System.Data.Entity.MigrateDatabaseToLatestVersion`2.InitializeDatabase(TContext context)
   at System.Data.Entity.Internal.InternalContext.<>c__DisplayClassf`1.<CreateInitializationAction>b__e()
   at System.Data.Entity.Internal.InternalContext.PerformInitializationAction(Action action)
   at System.Data.Entity.Internal.InternalContext.PerformDatabaseInitialization()
   at System.Data.Entity.Internal.LazyInternalContext.<InitializeDatabase>b__4(InternalContext c)
   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.LazyInternalContext.InitializeDatabase()
   at System.Data.Entity.Internal.InternalContext.Initialize()
   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.AsNoTracking()
   at System.Data.Entity.Infrastructure.DbQuery`1.AsNoTracking()

I can only guess MiniProfiler wraps the database connection with a profiling layer which appears to contain a bug.

This worked fine in 4.0.0-alpha6-83. I am using .NET Framework 4.7.

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 25 (23 by maintainers)

Commits related to this issue

Most upvoted comments

@elmcherqui thanks. I just noticed that your stack trace matches the one at the top of the thread. The error occurs when EF is trying to run migrations on startup, which explains why I couldn’t reproduce, as it is not something I ever do. But hopefully now I can reproduce the issue and start working on a fix.

Going to close this out since it’s really an EF issue (with hopefully a 6.3 release to resolve soon), but not much MiniProfiler can do here.

Most likely, “contextOwnsConnection” will determine who handles disposing of the connection. If the value is true, then I would expect the connection to be disposed when the context is disposed. If the value is false, then whoever provided the connection will be responsible for disposing of it regardless of what happens to the context. If the connection is provided by a dependency injection system then it should most likely be set to false.