Getting Null Exception for Entity Framework core 1.1

I am getting null exception for configure Service. I am using Entity Framework 1.1, previously use core 1.0 and have no issue, not sure what I am missing here

Error In Startup.cs --> at Services.AddDbContext...
 {System.ArgumentNullException: Value cannot be null.
 Parameter name: connectionString
 at Microsoft.EntityFrameworkCore.Utilities.Check.NotEmpty(String value, String parameterName)
at   Microsoft.EntityFrameworkCore.SqlServerDbContextOptionsExtensions.UseSqlServer(D bContextOptionsBuilder optionsBuilder, String connectionString, Action`1 sqlServerOptionsAction)
at App.WebDashboard.Startup.<ConfigureServices>b__4_0(DbContextOptionsBuilder options)
at Microsoft.Extensions.DependencyInjection.EntityFrameworkServiceCollectionExtensions.DbContextOptionsFactory[TContext](IServiceProvider applicationServiceProvider, Action`2 optionsAction)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitScoped(ScopedCallSite scopedCallSite, ServiceProvider provider)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitConstructor(ConstructorCallSite constructorCallSite, ServiceProvider provider)
at  Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitScoped(ScopedCallSite scopedCallSite, ServiceProvider provider)
at Microsoft.Extensions.DependencyInjection.ServiceProvider.<>c__DisplayClass16_0.<RealizeService>b__0(ServiceProvider provider)
at Microsoft.Extensions.Internal.ActivatorUtilities.GetService(IServiceProvider sp, Type type, Type requiredBy, Boolean isDefaultParameterRequired)
at lambda_method(Closure , IServiceProvider , Object[] )
at Microsoft.AspNetCore.Mvc.Internal.TypeActivatorCache.CreateInstance[TInstance](IServiceProvider serviceProvider, Type implementationType)
at Microsoft.AspNetCore.Mvc.Controllers.DefaultControllerFactory.CreateController(ControllerContext context)
at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker. <InvokeNextResourceFilter>d__22.MoveNext()}
Startup.cs
 public void ConfigureServices(IServiceCollection services)
    {
        // Add framework services.
        services.AddApplicationInsightsTelemetry(Configuration);

        services.AddDbContext<TestDbContext>(options =>
           options.UseSqlServer(Configuration.GetConnectionString("UCASAppDatabase")));

        services.AddMvc();
    }
Connection string in appsetting.json
"ConnectionStrings": {
  "UCASAppDatabase": "Data Source=mydatasource;Initial Catalog=UCAS-DB;Integrated Security=True"
}
DbContext
 public class TestDbContext : DbContext
 {
    public TestDbContext(DbContextOptions<TestDbContext> options) : base(options)
    { }

    public DbSet<TestModel> TestModels { get; set; }

    protected override void OnModelCreating(ModelBuilder modelBuilder)
    {
        modelBuilder.Entity<TestModel>().ToTable("TestTable");
    }
}
Entity Class
[Table("TestTable")]
public class TestModel
{
    [Key]
    public int ID { get; set; }
    public string Name { get; set; }
}
Controller class where I am trying to read data
public class HomeController : Controller
{
    private readonly TestDbContext _context;
    public HomeController(TestDbContext context)
    {
        this._context = context;
    }

    public IActionResult About()
    {
        var query = (from b in _context.TestModels
                     select b).ToList();

        ViewData["Message"] = "Your application description page.";

        return View();
    }
Appsettings.json
 public Startup(IHostingEnvironment env)
    {
        var builder = new ConfigurationBuilder()
            .SetBasePath(env.ContentRootPath)
            .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
            .AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true)
            .AddEnvironmentVariables();

found the answer, need to sorted connection-String in appsettings.json

"Data": {
  "UCASAppDatabase": {
    "ConnectionString": "Data Source=mysource;Initial Catalog=UCAS-DB;Integrated Security=True;Persist Security Info=True"
  }
}

and in Startup.cs

public void ConfigureServices(IServiceCollection services)
    {
        services.AddApplicationInsightsTelemetry(Configuration);

        services.AddDbContext<TestDbContext>(options =>
           options.UseSqlServer(Configuration["Data:UCASAppDatabase:ConnectionString"]));

        services.AddMvc();
    }

null exception when I try to include a property which parent can be , ToListAsync(); But I get an exception of null reference. If I EntityFrameworkCore 2.0.0 as EF Core version. The stack trace is this: Entity Framework Core 1.1.1 ArgumentNullException Thrown For Connection String. You will notice that is null because in the settings file you spelt the key wrong


By convention, the file should be called appsettings.json, not appsetting.json. Can you make sure your Startup file is referencing it right?

Breaking changes, version 2.2 to 3.1, Obsolete members and compatibility switches in ASP.NET Core 2.2 were removed. Owin 3.1.0 and later, a temporary mitigation is outlined here. NET Core 1.1-era MVC precompilation tool was removed. NET Core 3.0 Preview 8, the null string throws an exception when used as a property name, and  I am using Entity Framework Core 1.1, but I'm having trouble with migrations through PMC. My initial migration worked successfully, but after updating the database and re-launching VS 2017 I get a null exception on the contentRootPath argument when attempting to migrate.


I had the same problem. In my property class I just added the key DataAnnotations for the primary key attribute as follows and error was solved.

using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Text;

namespace Treat_Data.Model
{
    public class Restaurant
    {
        [Key]
        public int Restaurant_ID { get; set; }//this is the primary key
        public string Name { get; set; }
        public string Address { get; set; }
        public string Open_Hours { get; set; }

    }
}

DbContext Class (Microsoft.EntityFrameworkCore), your entities. DbContext is a combination of the Unit Of Work and Repository patterns. EntityFrameworkCore.dll If no entity is found, then null is returned. I am getting following strange exceptions. I already saw following thread discussing about downgrading Microsoft.EntityFrameworkCore.Tools to 1.1.1 which I already did, but still these exceptions are appearing. System.ArgumentNullException: Value cannot be null.


[PDF] Getting started with ASP.NET Core MVC and Entity Framework Core , Core 1.1 MVC web applications using Entity Framework Core 1.1 and Visual Studio 2017. grade -- null means a grade isn't known or hasn't been assigned yet. If an exception that derives from DbUpdateException is caught while the. I am getting following strange exceptions. I already saw following thread discussing about downgrading Microsoft.EntityFrameworkCore.Tools to 1.1.1 which I already did, but still these exceptions are appearing. System.ArgumentNullException: Value cannot be null.


7.2.2 Scaffolding an Existing Database in EF Core, Handling NULL Dates Scaffolding a database produces an Entity Framework model from an existing database. If you are upgrading from EF Core 1.1 to EF Core 2.0 or 2.1, you must remove the MySql.Data. If this is an upgrade, remove the following reference to that package from the . csproj file (version 2.0.3 in this  Stack Overflow for Teams is a private, secure spot for you and your coworkers to find and share information. Learn more Why am I getting a NullReferenceException in System.Data.Entity.dll (Entity Framework)?


dotConnect for Dynamics CRM History, NullReferenceException by License Wizard is fixed Entity Framework 6.4 is supported; Entity Framework Core 3.1 is supported; The new \Entity\EFCore3\​Devart. Entity Framework Core 1.1.2 is supported; The bug with paging in EF Core is  Introducing EntityFramework.Exceptions Dec 11, 2018 4 min read Entity Framework When using Entity Framework Core for data access all database exceptions are wrapped in DbUpdateException .