Closed
Description
Hi,
ref: https://github.com/rikrak/EF6_2_InitialisationError
I've just upgraded to EF6.2 and I receive a NullReferenceException on startup. I've done a bit of digging around and I think it's results from having Glimpse.EF6 installed.
The exception appears to come from a call to DbMigrator.GetPendingMigrations().
After a bit of debugging, it looks like a DbConnection is disposed of, which causes the GlimpseDbConnection to set the InnerConnection to null. I think another call is then made to the same connection after disposal, which then causes a NullReferenceException.
The same code worked with EF 6.1.3
source Error:
Line 46: var migrator = new DbMigrator(_configuration);
Line 47:
Line 48: if (migrator.GetPendingMigrations().Any())
Line 49: {
Line 50: migrator.Update();
Source File: D:\Dev\Src\EF6_2_InitialisationError\UI.Web\UnitOfWork\DbInitialiser.cs Line: 48
Stack Trace:
[NullReferenceException: Object reference not set to an instance of an object.]
Glimpse.Ado.AlternateType.GlimpseDbConnection.get_State() +6
System.Data.Entity.Internal.RepositoryBase.CreateConnection() +25
System.Data.Entity.Migrations.History.HistoryRepository.QueryExists(String contextKey) +82
System.Data.Entity.Migrations.History.HistoryRepository.Exists(String contextKey) +39
System.Data.Entity.Migrations.History.HistoryRepository.GetPendingMigrations(IEnumerable`1 localMigrations) +46
System.Data.Entity.Migrations.DbMigrator.GetPendingMigrations() +29
UI.Web.UnitOfWork.CreateAndMigrateDatabaseInitializer`2.System.Data.Entity.IDatabaseInitializer<TContext>.InitializeDatabase(TContext context) in D:\Dev\Src\EF6_2_InitialisationError\UI.Web\UnitOfWork\DbInitialiser.cs:48
System.Data.Entity.Internal.<>c__DisplayClassf`1.<CreateInitializationAction>b__e() +76
System.Data.Entity.Internal.InternalContext.PerformInitializationAction(Action action) +60
System.Data.Entity.Internal.InternalContext.PerformDatabaseInitialization() +357
System.Data.Entity.Internal.LazyInternalContext.<InitializeDatabase>b__4(InternalContext c) +7
System.Data.Entity.Internal.RetryAction`1.PerformAction(TInput input) +111
System.Data.Entity.Internal.LazyInternalContext.InitializeDatabaseAction(Action`1 action) +198
System.Data.Entity.Internal.LazyInternalContext.InitializeDatabase() +73
System.Data.Entity.Internal.InternalContext.Initialize() +30
System.Data.Entity.Internal.InternalContext.ForceOSpaceLoadingForKnownEntityTypes() +48
System.Data.Entity.DbContext.System.Data.Entity.Infrastructure.IObjectContextAdapter.get_ObjectContext() +25
UI.Web.UnitOfWork.SampleContext..ctor() in D:\Dev\Src\EF6_2_InitialisationError\UI.Web\UnitOfWork\SampleContext.cs:13
UI.Web.MvcApplication.Application_Start() in D:\Dev\Src\EF6_2_InitialisationError\UI.Web\Global.asax.cs:23
[HttpException (0x80004005): Object reference not set to an instance of an object.]
System.Web.HttpApplicationFactory.EnsureAppStartCalledForIntegratedMode(HttpContext context, HttpApplication app) +477
System.Web.HttpApplication.RegisterEventSubscriptionsWithIIS(IntPtr appContext, HttpContext context, MethodInfo[] handlers) +118
System.Web.HttpApplication.InitSpecial(HttpApplicationState state, MethodInfo[] handlers, IntPtr appContext, HttpContext context) +176
System.Web.HttpApplicationFactory.GetSpecialApplicationInstance(IntPtr appContext, HttpContext context) +350
System.Web.Hosting.PipelineRuntime.InitializeApplication(IntPtr appContext) +303
[HttpException (0x80004005): Object reference not set to an instance of an object.]
System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +678
System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +90
System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +188