【问题标题】:Entity Framwork: error 0194: Multiple versions were encountered实体框架:错误 0194:遇到多个版本
【发布时间】:2017-05-10 09:10:42
【问题描述】:

我在 SQL Server 上使用实体框架工作了几年,但这个错误对我来说是新的。

我使用 EDMX 模型创建了一个库项目 (DLL)。

然后,我通过一个小控制台应用程序对其进行了测试,它可以正常工作。

最后,我尝试在需要这个 DLL 的实际项目中使用它,结果……它显然不起作用!!

我得到的错误是:

System.Data.Entity.Core.MetadataException:指定的架构不是 有效的。错误:错误 0194:将所有工件加载到 ItemCollection 必须具有相同的版本。有多个版本 遇到过。

完整的stackTrace是:

System.Data.Entity.Core.MetadataException:指定的架构无效。错误: 错误 0194:加载到 ItemCollection 中的所有工件必须具有相同的版本。遇到了多个版本。 在 System.Data.Entity.Core.Metadata.Edm.EdmItemCollection.LoadItems(IEnumerable1 xmlReaders, IEnumerable1 sourceFilePaths,SchemaDataModelOption dataModelOption,DbProviderManifest providerManifest,ItemCollection itemCollection,布尔 throwOnError) 在 System.Data.Entity.Core.Metadata.Edm.EdmItemCollection.Init(IEnumerable1 xmlReaders, IEnumerable1 filePaths,布尔 throwOnError) 在 System.Data.Entity.Core.Metadata.Edm.EdmItemCollection..ctor(IEnumerable1 xmlReaders, IEnumerable1 filePaths,布尔跳过初始化) 在 System.Data.Entity.Core.Metadata.Edm.MetadataCache.LoadEdmItemCollection(MetadataArtifactLoader 加载器) 在 System.Data.Entity.Core.Metadata.Edm.MetadataCache.c__DisplayClass5.b__0(String k) 在 System.Collections.Concurrent.ConcurrentDictionary2.GetOrAdd(TKey key, Func2 valueFactory) 在 System.Data.Entity.Core.Metadata.Edm.MetadataCache.GetMetadataWorkspace(DbConnectionOptions EffectiveConnectionOptions) 在 System.Data.Entity.Core.EntityClient.EntityConnection.GetMetadataWorkspace() 在 System.Data.Entity.Core.Objects.ObjectContext..ctor(EntityConnection 连接,布尔 isConnectionConstructor,ObjectQueryExecutionPlanFactory objectQueryExecutionPlanFactory,Translator 转换器,ColumnMapFactory columnMapFactory) 在 System.Data.Entity.Internal.InternalConnection.CreateObjectContextFromConnectionModel() 在 System.Data.Entity.Internal.LazyInternalContext.InitializeContext() 在 System.Data.Entity.Internal.InternalContext.GetEntitySetAndBaseTypeForType(类型 entityType) 在 System.Data.Entity.Internal.Linq.InternalSet1.Initialize() in System.Data.Entity.Internal.Linq.InternalSet1.get_InternalContext() 在 System.Data.Entity.Infrastructure.DbQuery1.System.Linq.IQueryable.get_Provider() in System.Linq.Queryable.FirstOrDefault[TSource](IQueryable1 源中,Expression1 predicate) in MailGunSender.MailManager.SendMail(String from, List1 收件人,List1 ccs, List1 ccns,字符串主题,字符串文本,字符串路径附件)在 xxx:riga 261

当然,我已经在调用者项目中安装了实体框架(使用 Nuget),就像我为测试器控制台项目所做的那样。但在这里它给了我这个错误。你知道为什么吗?

我的连接字符串由以下代码管理:

public partial class Entities : DbContext
{
    public Entities(string nameOrConnectionString)
        : base(nameOrConnectionString)
    {

    }

    public void Close()
    {
        this.Dispose();
    }

    public static string GetConnectionString(string server, string db, string user, string pwd)
    {
        string cn = "Server=" + server;
        cn += ";Database=" + db;
        cn += ";uid=" + user;
        cn += ";Pwd=" + pwd;
        var providerSB = new SqlConnectionStringBuilder(cn);
        var efConnection = new EntityConnectionStringBuilder();
        efConnection.Provider = "System.Data.SqlClient";
        efConnection.ProviderConnectionString = providerSB.ConnectionString;
        efConnection.Metadata = @"res://*";
        return efConnection.ToString();
    }
}

【问题讨论】:

  • 你的调用者项目是什么?例如。 ASP.NET MVC,WinForms? - 打开 NuGet 管理器检查您在所有项目中安装的实体框架包版本是否相同
  • 您有多个 .edmx 文件吗?您是否尝试过刷新或重新创建任何旧文件。
  • @Scrobi 我只有一个 edmx 文件,在 dll 中
  • @LukeTO'Brien 调用者项目是 Windows 服务,而测试调用者项目是控制台应用程序
  • 所有项目和 dll 是否都针对同一版本的 .Net?

标签: c# .net entity-framework linq metadata


【解决方案1】:

我刚刚偶然发现this article,这个人也有类似的问题,这与实体的唯一名称有关。
他还参考了另外两篇文章。

也许它适用于你的情况。

【讨论】:

  • 这个答案要更新了,链接不是堆栈溢出的答案,原因正是这里发生的事情。链接坏了
  • @catbadger 很抱歉,它曾一度奏效...您是否正在寻找您遇到的问题的答案?
  • @catbadger 也许您应该创建一个新问题?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2016-10-17
  • 1970-01-01
  • 2015-05-14
  • 1970-01-01
  • 1970-01-01
  • 2013-06-16
  • 2017-03-16
相关资源
最近更新 更多