【问题标题】:ASP.net vNext and Entity Framework 6ASP.net vNext 和实体框架 6
【发布时间】:2015-05-20 05:50:25
【问题描述】:

是否可以在预发布的 ASP.net vNext 下运行 EF6? EF7 没有我需要的某些功能,但我想在 .NET Core 中对我的应用程序进行原型设计。

我收到以下错误:

FileLoadException: A strongly-named assembly is required. 
(Exception from HRESULT: 0x80131044) Unknown location

FileLoadException: Could not load file or assembly
'EntityFramework.SqlServer, Version=6.0.0.0, Culture=neutral,
PublicKeyToken=b77a5c561934e089' or one of its dependencies. 
A strongly-named assembly is required. (Exception from HRESULT: 0x80131044)

我知道 .NET Core 不支持强命名程序集,但据我所知,我在 aspnet50 框架而不是 aspnetcore50 下运行服务器。

我的 project.json 看起来像这样:

{
    "webroot": "wwwroot",
    "version": "1.0.0-*",
    "dependencies": {
        "EntityFramework": "6.1.1",
        "Microsoft.AspNet.Mvc": "6.0.0-beta3",
        /* "Microsoft.AspNet.Mvc.WebApiCompatShim": "6.0.0-beta3", */
        "Microsoft.AspNet.Diagnostics": "1.0.0-beta3",
        "Microsoft.AspNet.Diagnostics.Entity": "7.0.0-beta3",
        "Microsoft.AspNet.Identity.EntityFramework": "3.0.0-beta3",
        "Microsoft.AspNet.Security.Cookies": "1.0.0-beta3",
        "Microsoft.AspNet.Server.IIS": "1.0.0-beta3",
        "Microsoft.AspNet.Server.WebListener": "1.0.0-beta3",
        "Microsoft.AspNet.StaticFiles": "1.0.0-beta3",
        "Microsoft.Framework.ConfigurationModel.Json": "1.0.0-beta3",
        "Microsoft.Framework.CodeGenerators.Mvc": "1.0.0-beta3",
        "Microsoft.Framework.Logging": "1.0.0-beta3",
        "Microsoft.Framework.Logging.Console": "1.0.0-beta3",
        "Microsoft.VisualStudio.Web.BrowserLink.Loader": "14.0.0-beta3",
        "Tricycle.SqlPlatform.EntityFramework": "1.0.0-*"
    },
    "commands": {
        /* Change the port number when you are self hosting this application */
        "web": "Microsoft.AspNet.Hosting --server Microsoft.AspNet.Server.WebListener --server.urls http://localhost:5000",
        "gen": "Microsoft.Framework.CodeGeneration",
    },
    "frameworks": {
        "aspnet50": {
            "dependencies": {
                "Tricycle.Studio.ContentManager.Client": "1.0.0-*"
            }
        },
        //"aspnetcore50": { }
    },
    "exclude": [
        "wwwroot",
        "node_modules",
        "bower_components"
    ],
    "bundleExclude": [
        "node_modules",
        "bower_components",
        "**.kproj",
        "**.user",
        "**.vspscc"
    ],
    "scripts": {
        "postrestore": [ "npm install" ],
        "prepare": [ "grunt bower:install" ]
    }
}

EF 类是在一个单独的项目 (Tricycle.Studio.ContentManager.Client) 中使用以下 project.json 定义的:

{
    "version": "1.0.0-*",
    "dependencies": {
        "EntityFramework": "6.1.1",
    },

    "frameworks": {
        "aspnet50": {
            "dependencies": {
                "System.Data.Common": "1.0.0-beta2",
                "System.Data.SqlClient": "1.0.0-beta2"
            }
        },
        //"aspnetcore50" : {
        //    "dependencies": {
        //        "System.Runtime": "4.0.20-beta-22523"
        //    }
        //}
    }
}

【问题讨论】:

    标签: asp.net entity-framework asp.net-core


    【解决方案1】:

    您不能将Microsoft.AspNet.Identity.EntityFramework 与 EF6 一起使用,因为它依赖于 EF7。

    根据您的 project.json 文件,运行时将同时加载 EF6 和 EF7(由于 Identity)。这种行为是不可预测的。

    另外,不要混合使用 beta2beta3 包。那肯定是麻烦。

    【讨论】:

    • 谢谢!删除 Microsoft.AspNet.Identity.EntityFramework 似乎已修复它。关于 beta2/3 - 这些软件包似乎只在 beta2 中可用。
    • 啊,很好的发现,@Victor。初创公司的所有新玩具都让我忽略了这一点。 +1
    猜你喜欢
    • 1970-01-01
    • 2023-03-03
    • 2014-11-08
    • 2014-07-28
    • 1970-01-01
    • 1970-01-01
    • 2013-10-30
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多