简体   繁体   中英

System.MissingMethodException after upgrading from EF 6.0 Beta to RC

what does this mean?

System.MissingMethodException was unhandled by user code
HResult=-2146233069 Message=Method not found: 'System.Data.Entity.ModelConfiguration.Configuration.PrimitivePropertyConfiguration System.Data.Entity.ModelConfiguration.Configuration.StructuralTypeConfiguration 1.Property(System.Linq.Expressions.Expression 12<!0,!!0>>)'. Source=Att.Uds.DataLayerMappings StackTrace: at Att.Uds.DataLayerMappings.ItemTypeItemConfiguration..ctor() at Att.Uds.DataLayerMappings.UdsContext.OnModelCreating(DbModelBuilder modelBuilder) in c:\\TFS\\ATS-MSDev\\UDS\\Dev\\Code\\Att.Uds.DataLayerMappings\\UdsContext.cs:line 163 at System.Data.Entity.DbContext.CallOnModelCreating(DbModelBuilder modelBuilder) at System.Data.Entity.Internal.LazyInternalContext.CreateModelBuilder() at System.Data.Entity.Internal.LazyInternalContext.CreateModel(LazyInternalContext internalContext) at System.Data.Entity.Internal.RetryLazy2.GetValue(TInput input) InnerException:

Error happens on this class:

namespace Contoso.Fabrikam.DataLayerMappings
{ 
  public abstract class NamedEntityConfiguration<TEntity> : EntityBaseConfiguration<TEntity> where TEntity : NamedEntity
  {
    public ConfigurationColumn NameColumn;
    protected new int LastOrdinalPosition
    {
      get
      {
        return (NameColumn.Ordinal);
      }
    }
    public NamedEntityConfiguration() <=== EXCEPTION HERE
    {
      NameColumn = new ConfigurationColumn() { Ordinal = base.LastOrdinalPosition+1, Name = "Name", IsRequired = true, Length = 128 };
      this.Property(t => t.Name)
        .HasColumnName(NameColumn.Name)
        .HasColumnOrder(NameColumn.Ordinal)
        .HasMaxLength(NameColumn.Length);
      if(NameColumn.IsRequired)
      {
        this.Property(t => t.Name).IsRequired();
      }
    }
  }
}

Thank you

The reason why @Saber his answer works is because when you upgrade your project to a higher .NET Version, the project file is not upgraded automatically. For example, if you upgrade from .NET 4.0 to .NET 4.5 and edit the project file, you might see the following:

<Reference Include="EntityFramework">
      <HintPath>..\packages\EntityFramework.6.1.3\lib\net40\EntityFramework.dll</HintPath>
    </Reference>
    <Reference Include="EntityFramework.SqlServer">
      <HintPath>..\packages\EntityFramework.6.1.3\lib\net40\EntityFramework.SqlServer.dll</HintPath>
    </Reference>

You will have to change the reference to net45 instead of net40 . When removing the packages, this will produce the same behaviour.

I've encountered same error. It worked for me:

  1. Uninstall-Package EntityFramework in Package Manager Console
  2. Delete EntityFramework folder from 'packages' folder
  3. Install-Package EntityFramework in Package Manager Console

In my case I had to remove the EntityFramework.dll from this folder:

C:\\Windows\\Microsoft.NET\\assembly\\GAC_MSIL\\EntityFramework

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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