简体   繁体   English

实体框架构造函数上的NullReferenceException

[英]NullReferenceException on Entity Framework constructor

I have a DER.edmx , and in DER.Designer.cs there is this autogenerated code 我有一个DER.edmx ,在DER.Designer.cs有这个自动生成的代码

public SiGMAEntities(string connectionString) : base(connectionString, "SiGMAEntities")
{
    this.ContextOptions.LazyLoadingEnabled = true;
    OnContextCreated();
}

the line that throws the exception is 引发异常的行是

public SiGMAEntities(string connectionString) : base(connectionString, "SiGMAEntities")

A couple of days ago, everything worked perfectly but I had to re-install Windows for other reasons, and of course VS and SQL Server. 几天前,一切正常,但由于其他原因,我不得不重新安装Windows,当然还有VS和SQL Server。 The exception happened when I wanted to start working on the project again. 当我想再次开始该项目时,发生了例外。

Stack trace 堆栈跟踪

    [NullReferenceException: Object reference not set to an instance of an object.]
   System.Collections.Generic.Dictionary`2.System.Collections.IDictionary.Remove(Object key) +48
   System.Data.Metadata.Edm.MetadataWorkspace.RegisterDefaultObjectMappingItemCollection() +95
   System.Data.Metadata.Edm.MetadataWorkspace.GetItemCollection(DataSpace dataSpace, Boolean required) +124
   System.Data.Metadata.Edm.MetadataWorkspace.GetItemCollection(DataSpace dataSpace) +48
   System.Data.Objects.ObjectContext..ctor(EntityConnection connection, Boolean isConnectionConstructor) +438
   System.Data.Objects.ObjectContext..ctor(String connectionString) +65
   System.Data.Objects.ObjectContext..ctor(String connectionString, String defaultContainerName) +37
   AccesoADatos.SiGMAEntities..ctor(String connectionString) in E:\Documentos(NO BORRAR)\Documentos de GonDC\Facu\SiGMA\asd - Copy\trunk\AccesoADatos\DER.Designer.cs:79
   AccesoADatos.Conexion.crearSegunServidor() in E:\Documentos(NO BORRAR)\Documentos de GonDC\Facu\SiGMA\asd - Copy\trunk\AccesoADatos\Conexion.cs:27
   AccesoADatos.Datos.TiposDNI() in E:\Documentos(NO BORRAR)\Documentos de GonDC\Facu\SiGMA\asd - Copy\trunk\AccesoADatos\Datos.cs:14
   Herramientas.CargarCombos.cargarTipoDocumento(DropDownList& ddl) in E:\Documentos(NO BORRAR)\Documentos de GonDC\Facu\SiGMA\asd - Copy\trunk\Herramientas\CargarCombos.cs:30
   SiGMA._Default.Page_Load(Object sender, EventArgs e) in E:\Documentos(NO BORRAR)\Documentos de GonDC\Facu\SiGMA\asd - Copy\trunk\SiGMA\RegistrarUsuario.aspx.cs:26
   System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +51
   System.Web.UI.Control.OnLoad(EventArgs e) +92
   System.Web.UI.Control.LoadRecursive() +54
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +772

This can happen if you dont have the right connectionString specified in your App.config or web.config. 如果没有在App.config或web.config中指定正确的connectionString,则会发生这种情况。 Make sure that the running applications App.config or web.config respectively contains the connectionString that you specified when defining the database model. 确保正在运行的应用程序App.config或web.config分别包含您在定义数据库模型时指定的connectionString。 Something like this: 像这样:

<connectionStrings>
  <add name="SiGMAEntities" connectionString="metadata=res://*/xxx.csdl|res://*/xxx.ssdl|res://*/xxx.msl;provider=System.Data.SqlClient;provider connection string=&quot;xxx&quot;" providerName="System.Data.EntityClient"/>
</connectionStrings>

xxx is just a placeholder for your stuff xxx只是您的东西的占位符

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM