Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Asp.net Core EF options.UseInMemoryDatabase System.TypeLoadException

I used EF in Asp.net Core, but got below error in below code:

public class TodoContext : DbContext
{
    public TodoContext(DbContextOptions<TodoContext> options)
        : base(options)
    {

    }
    public DbSet<TodoItem> TodoItems { get; set; }

}

Error Message:

An exception of type 'System.TypeLoadException' occurred in Microsoft.EntityFrameworkCore.dll but was not handled in user code

Additional information: Could not load type 'Microsoft.Extensions.DependencyInjection.Extensions.ServiceCollectionExtensions' from assembly 'Microsoft.Extensions.DependencyInjection.Abstractions, Version=1.1.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'.

Here is my Project.json

{
  "dependencies": {
    "Microsoft.NETCore.App": {
      "version": "1.0.1",
      "type": "platform"
    },
    "Microsoft.AspNetCore.Diagnostics": "1.0.0",

    "Microsoft.AspNetCore.Server.IISIntegration": "1.0.0",
    "Microsoft.AspNetCore.Server.Kestrel": "1.0.1",
    "Microsoft.Extensions.Logging.Console": "1.0.0",
    //Dependence for MVC
    "Microsoft.AspNetCore.Mvc": "1.1.1",
    "Microsoft.AspNetCore.StaticFiles": "1.1.0",
    "Microsoft.Extensions.Configuration.FileExtensions": "1.1.0",
    "Microsoft.Extensions.Configuration.Json": "1.1.0",
    //Dependence for EF
    "Microsoft.EntityFrameworkCore": "1.1.0",
    "Microsoft.EntityFrameworkCore.InMemory": "1.0.0-rc2-final"
    //Dependence for EF with SQL, this is avalible under VS 2017 RC
    //"Microsoft.EntityFrameworkCore.SqlServer": "1.1.0",
    //Entity Framework commands to maintain the database
    //"Microsoft.EntityFrameworkCore.Tools": "1.0.0-preview4-final"
  },

  "tools": {
    "Microsoft.AspNetCore.Server.IISIntegration.Tools": "1.0.0-preview2-final"
  },

  "frameworks": {
    "netcoreapp1.0": {
      "imports": [
        "dotnet5.6",
        "portable-net45+win8"
      ]
    }
  },

  "buildOptions": {
    "emitEntryPoint": true,
    //used for Razor pages which are compiled at runtime,and the compiler needs access to reference assemblies,
    //to make sure it compiles correctly
    "preserveCompilationContext": true
  },

  "runtimeOptions": {
    "configProperties": {
      "System.GC.Server": true
    }
  },

  "publishOptions": {
    "include": [
      "wwwroot",
      "web.config"
    ]
  },

  "scripts": {
    "postpublish": [ "dotnet publish-iis --publish-folder %publish:OutputPath% --framework %publish:FullTargetFramework%" ]
  }
}

Any help would be appreciated.
Reards,
Edward

like image 468
Edward Avatar asked Mar 01 '17 10:03

Edward


1 Answers

After trying, I changed "1.0.0-rc2-final" to "1.1.0" which I already have tried, but I found there is an warning, "Dependency conflict. CoreMVCWebAPI 1.0.0 expected Microsoft.EntityFrameworkCore.InMemory >= 1.1.0 but received 1.0.0-rc2-final", after install this package manually instead of only changing project.json, it works now.

Install-Package Microsoft.EntityFrameworkCore.InMemory
like image 76
Edward Avatar answered Nov 16 '22 15:11

Edward