NullReferenceException on Code First Migrations when Glimpse is installed
See original GitHub issueHi,
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
Issue Analytics
- State:
- Created 6 years ago
- Comments:18 (9 by maintainers)
Top Results From Across the Web
Null Reference Exception thrown when adding migration in ...
i have been using entity framework code first migration in my mvc project. But recently after modifying my model class and adding new...
Read more >Why "System.NullReferenceException " is occurred in ...
I am new to Code First migration. When i try to migrate , "System.NullReferenceException " exception has showed in Package Manager Console.
Read more >Updating to EF 6.2.0 from EF 6.1.3 causes cannot access a ...
It's the same as reported in #398: NullReferenceException on Code First Migrations when Glimpse is installed. According to the status, it's already fixed...
Read more >System.NullReferenceException message in creating ...
Hi everyone, I created a localdb sql server file(School.mdf) in the App_Data folder in an MVC project using .Net Framework 4.8.
Read more >C# 8.0 Features: A Glimpse of the Future
In short, you have several options. As soon as you convince the compiler that your code offers no risk of throwing a null...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
When is a 6.3 package going to be released? I’m still getting bug reports on this every few weeks. What do I tell them about something fixed exactly a year ago now?
Can we please release 6.3? Or even a 6.2.1 with just the fixes? Please?
cc @divega
+1 - just hit this. I am downgrading to 6.1.3 for now.