Could not load file or assembly 'Microsoft.Ent

2020-06-16 09:07发布

I have a Asp.Net Core project targeting .NET 462 and it was working with Asp.Net Core version 1.0.1. After upgrading to "1.1.0" I got this error:

FileLoadException: Could not load file or assembly 'Microsoft.EntityFrameworkCore.SqlServer, Version=1.1.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

project.json

"dependencies": {
    "AspNet.Mvc.TypedRouting": "1.2.0",
    "AutoMapper": "5.1.1",
    "AutoMapper.Extensions.Microsoft.DependencyInjection": "1.1.2",
    "BundlerMinifier.Core": "2.2.306",
    "JetBrains.Annotations": "10.2.1",
    "libphonenumber-csharp": "7.7.4",
    "Microsoft.AspNetCore.Authentication.Cookies": "1.1.0",
    "Microsoft.AspNetCore.Authentication.Facebook": "1.1.0",
    "Microsoft.AspNetCore.Authentication.Google": "1.1.0",
    "Microsoft.AspNetCore.Authentication.MicrosoftAccount": "1.1.0",
    "Microsoft.AspNetCore.Authentication.OpenIdConnect": "1.1.0",
    "Microsoft.AspNetCore.Authentication.Twitter": "1.1.0",
    "Microsoft.AspNetCore.Diagnostics": "1.1.0",
    "Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore": "1.1.0",
    "Microsoft.AspNetCore.Identity.EntityFrameworkCore": "1.1.0",
    "Microsoft.AspNetCore.Mvc": "1.1.0",
    "Microsoft.AspNetCore.Razor.Tools": "1.1.0-preview4-final",
    "Microsoft.AspNetCore.Server.IISIntegration": "1.1.0",
    "Microsoft.AspNetCore.Server.Kestrel": "1.1.0",
    "Microsoft.AspNetCore.Server.Kestrel.Https": "1.1.0",
    "Microsoft.AspNetCore.Session": "1.1.0",
    "Microsoft.AspNetCore.StaticFiles": "1.1.0",
    "Microsoft.EntityFrameworkCore": "1.1.0",
    "Microsoft.EntityFrameworkCore.SqlServer": "1.1.0",
    "Microsoft.EntityFrameworkCore.Tools": "1.1.0-preview4-final",
    "Microsoft.Extensions.Configuration": "1.1.0",
    "Microsoft.Extensions.Configuration.Abstractions": "1.1.0",
    "Microsoft.Extensions.Configuration.CommandLine": "1.1.0",
    "Microsoft.Extensions.Configuration.EnvironmentVariables": "1.1.0",
    "Microsoft.Extensions.Configuration.Json": "1.1.0",
    "Microsoft.Extensions.Configuration.UserSecrets": "1.1.0",
    "Microsoft.Extensions.Logging": "1.1.0",
    "Microsoft.Extensions.Logging.Console": "1.1.0",
    "Microsoft.Extensions.Logging.Debug": "1.1.0",
    "Microsoft.Extensions.Options.ConfigurationExtensions": "1.1.0",
    "Microsoft.VisualStudio.Web.BrowserLink.Loader": "14.1.0",
    "Microsoft.VisualStudio.Web.CodeGenerators.Mvc": "1.1.0-preview4-final",
    "MotleyFlash": "0.3.0",
    "MotleyFlash.AspNetCore.MessageProviders": "0.2.0",
    "MotleyFlash.AspNetCore.ViewHelpers": "0.2.0",
    "SendGrid.NetCore": "1.0.0-rtm-00002",
    "System.Interactive.Async": "3.1.0",
    "Twilio": "4.7.2"
},
"frameworks": {
    "net462": {
        "dependencies": {
            "TaxiGun.Server.IdentityServer.Data": {
                "target": "project"
            },
            "TaxiGun.Server.Services": {
                "target": "project"
            }
        }
    }
},

When I take a look at on build output folder, I can see all the libraries in a proper version except "Microsoft.EntityFrameworkCore.SqlServer": Microsoft.EntityFrameworkCore.SqlServer

I think it is causing the problem. But I just can not figure out why the version is wrong? Is it because the nuget package has a wrong version inside?

2条回答
戒情不戒烟
2楼-- · 2020-06-16 09:37

Complete project references clean-up solved my problem.

  1. Delete all bin/obj folders
  2. Delete all project.lock.json files
  3. Delete local Nuget repository cache (computer one)
  4. Remove all references from project.json file and add only required ones (with the help of R#)
  5. nuget udpate, dotnet restore = project is running

When I'm thinking about it again, maybe only point 4 was important?

查看更多
孤傲高冷的网名
3楼-- · 2020-06-16 09:48

updated Pomelo.EntityFrameworkCore.MySql in .csproj file to the latest version 3.1.1 to fix issue.

查看更多
登录 后发表回答