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

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

问题描述


没有找到方法:'空虚System.Data.Objects.ObjectContextOptions.set_UseConsistentNullReferenceBehavior(Boolean)'。


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

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

public class EFDbContext:DbContext
{
public DbSet< Blog>博客{get;组;
}

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上查找错误,但没有出现我不太确定什么错误是指的。
我在下面添加了一个stacktrace的代码段,以防它有帮助。


[MissingMethodException:找不到方法:'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 .InternalSet 1.Initialize()+137

System.Data.Entity.Internal.Linq.InternalSet
1.get_InternalContext()
+ 38 System.Data.Entity.Internal.Linq.InternalSet 1.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。



如果您打算使用.NET 4.5,请确保在运行代码的计算机上安装了.NET 4.5。 VS11为您安装.NET 4.5,但您也可以在非开机设备上安装运行时。



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



更新: p>

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

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

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

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


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

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

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();
    }
}

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: '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

解决方案

Looks like you are using the EF5 EntityFramework.dll but then running with .NET 4 installed instead of .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.

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.

Update:

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

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天全站免登陆