efcore icon indicating copy to clipboard operation
efcore copied to clipboard

Microsoft.Data.Entity.Internal.DbContextServices.get_DatabaseProviderServices()Will object reference not set to an instance of an object.

Open blueskybcl opened this issue 10 years ago • 6 comments

Application startup exception: System.Reflection.TargetInvocationException: The goal of call exception occurred. ---> System.NullReferenceException: Will object reference not set to an instance of an object. at Microsoft.Data.Entity.Internal.DbContextServices.get_DatabaseProviderServices() at Microsoft.Data.Entity.Infrastructure.RelationalEntityFrameworkServicesBuilderExtensions.GetProviderServices(IServiceProvider serviceProvider) at Microsoft.Data.Entity.Infrastructure.RelationalEntityFrameworkServicesBuilderExtensions.<>c.b__0_16(IServiceProvider p) at Microsoft.Extensions.DependencyInjection.ServiceLookup.FactoryService.Invoke(ServiceProvider provider) at Microsoft.Extensions.DependencyInjection.ServiceProvider.ScopedCallSite.Invoke(ServiceProvider provider) at Microsoft.Extensions.DependencyInjection.ServiceProvider.<>c__DisplayClass12_0.b__0(ServiceProvider provider) at Microsoft.Extensions.DependencyInjection.ServiceProvider.GetService(Type serviceType) at Microsoft.Extensions.DependencyInjection.ServiceProviderExtensions.GetService[T](IServiceProvider provider) at ContosoBooks.Models.SampleData.Initialize(IServiceProvider serviceProvider) position E:\AllProjects\ASP.NET5\ContosoBooks\src\ContosoBooks\Models\SampleData.cs:row number 14 at ContosoBooks.Startup.Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)

blueskybcl avatar Dec 16 '15 01:12 blueskybcl

resolved i use if (context.Database == null) { throw new Exception("DB is null"); } replace if (serviceProvider.GetService().Exists())

blueskybcl avatar Dec 16 '15 01:12 blueskybcl

@blueskybcl is there a chance you could provide repro code to help us make sure this isn't an issue in EF?

divega avatar Dec 16 '15 01:12 divega

@divega I was in accordance with the practice of http://docs.asp.net/projects/mvc/en/latest/tutorials/mvc-with-entity-framework.html, the result is wrong “Next, we’ll create some sample data. Add a class named SampleData in the Models folder with the following code:”

error in class of SampleData

If it is me, please tell me.

blueskybcl avatar Dec 18 '15 08:12 blueskybcl

Reopening so that we can see this in triage.

divega avatar Dec 18 '15 17:12 divega

@divega ef version is 7.0.0.0-final-rc1

blueskybcl avatar Dec 19 '15 00:12 blueskybcl

@divega source at https://github.com/blueskybcl/ContosoBooks

blueskybcl avatar Dec 19 '15 08:12 blueskybcl