任何人都可以发现为什么我在测试 EF 5 beta 时不断收到此错误 [英] Can anyone spot why I keep getting this error testing the EF 5 beta

查看:21
本文介绍了任何人都可以发现为什么我在测试 EF 5 beta 时不断收到此错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

安装了 Visual Studio 11 测试版,想测试 EF 5 测试版,但一直遇到这个错误.

Installed visual studio 11 beta as wanted to test EF 5 beta but keep hitting this an error.

找不到方法:'Void System.Data.Objects.ObjectContextOptions.set_UseConsistentNullReferenceBehavior(Boolean)'.

Method not found: 'Void System.Data.Objects.ObjectContextOptions.set_UseConsistentNullReferenceBehavior(Boolean)'.

项目是一个新的空白 MVC3 应用程序,下面是一些说明错误如何发生的代码.

Project is a new blank MVC3 application and below is some code that illustrate how the error happens.

public class Blog
{
    public int Id { get; set; }
    public string Name { get; set; }
}

public class EFDbContext : DbContext
{
    public DbSet<Blog> Blogs { get; set; }
}

public class HomeController : Controller
{
    protected EFDbContext Db = new EFDbContext();

    public ActionResult Index()
    {
        Blog B = new Blog();
        B.Name = "Test";            
        Db.Blogs.Add(B);
        Db.SaveChanges();
        return View();
    }
}

在 google 上查找错误,但什么也没找到,我不太确定错误指的是什么.我在下面添加了堆栈跟踪的片段,以防万一.

Looked for the error on google but nothing came up and i'm not quite sure what error is referring to. I added a snippet of the stacktrace below in case it will help.

[MissingMethodException: Method not found: 'VoidSystem.Data.Objects.ObjectContextOptions.set_UseConsistentNullReferenceBehavior(Boolean)'.]System.Data.Entity.Internal.LazyInternalContext.InitializeContext() +0System.Data.Entity.Internal.InternalContext.Initialize() +31
System.Data.Entity.Internal.InternalContext.GetEntitySetAndBaseTypeForType(类型实体类型) +39
System.Data.Entity.Internal.Linq.InternalSet1.Initialize() +137
System.Data.Entity.Internal.Linq.InternalSet
1.get_InternalContext()+38 System.Data.Entity.Internal.Linq.InternalSet1.ActOnSet(Action action, EntityState newState, Object entity, String methodName) +236
System.Data.Entity.Internal.Linq.InternalSet
1.Add(Object entity) +200System.Data.Entity.DbSet`1.Add(TEntity entity) +72

[MissingMethodException: Method not found: 'Void System.Data.Objects.ObjectContextOptions.set_UseConsistentNullReferenceBehavior(Boolean)'.] System.Data.Entity.Internal.LazyInternalContext.InitializeContext() +0 System.Data.Entity.Internal.InternalContext.Initialize() +31
System.Data.Entity.Internal.InternalContext.GetEntitySetAndBaseTypeForType(Type entityType) +39
System.Data.Entity.Internal.Linq.InternalSet1.Initialize() +137
System.Data.Entity.Internal.Linq.InternalSet
1.get_InternalContext() +38 System.Data.Entity.Internal.Linq.InternalSet1.ActOnSet(Action action, EntityState newState, Object entity, String methodName) +236
System.Data.Entity.Internal.Linq.InternalSet
1.Add(Object entity) +200 System.Data.Entity.DbSet`1.Add(TEntity entity) +72

推荐答案

看起来您正在使用 EF5 EntityFramework.dll,但随后安装了 .NET 4 而不是 .NET 4.5.

Looks like you are using the EF5 EntityFramework.dll but then running with .NET 4 installed instead of .NET 4.5.

如果您打算以 .NET 4.5 为目标,请确保在运行代码的机器上安装了 .NET 4.5.VS11 会为您安装 .NET 4.5,但您也可以在非开发机器上仅安装运行时.

If you are intending to target .NET 4.5, then make sure that .NET 4.5 is installed on the machine on which you are running the code. VS11 installs .NET 4.5 for you, but you can also install just the runtime on a non-dev machine.

如果您打算以 .NET 4 为目标,请确保您的项目设置为以 .NET 4 为目标,然后卸载并重新安装 EF5 NuGet 包.您必须卸载并重新安装,因为 NuGet 不会在重新定位项目时自动更改正在使用的程序集.

If you are intending to target .NET 4, then make sure that you project is set to target .NET 4 and then uninstall and reinstall the EF5 NuGet package. You must uninstall and reinstall because NuGet won't change the assembly in use automatically when the project is re-taregted.

更新:

如果您仍然安装了 EF June CTP 或未能正确卸载,您也可能会看到此异常.安装VS11前请尝试完全卸载June CTP.如果您仍然看到问题,请以管理员身份打开开发人员命令提示符"并运行:

You may also see this exception if you still have the EF June CTP installed or if it failed to uninstall correctly. Please try to uninstall the June CTP fully before installing VS11. If you still see problems them open a "Developer Command Prompt" as Administrator and run:

gacutil /u System.Data.Entity,Version=4.2.0.0,Culture=neutral,PublicKeyToken=b77a5c561934e089

如果仍然失败,那么您可以尝试从 GAC 中强制卸载:

If this still fails, then you can attempt to force the uninstall from the GAC with:

gacutil /uf System.Data.Entity,Version=4.2.0.0,Culture=neutral,PublicKeyToken=b77a5c561934e089

这篇关于任何人都可以发现为什么我在测试 EF 5 beta 时不断收到此错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆