首页 > 解决方案 > 无法加载文件或程序集 mscorlib.dll!System.AppDomain.OnAssemblyResolveEvent

问题描述

当我在 VS 2019 IDE 中运行我的 Winforms XAF 实体框架应用程序时

鉴于我在公共语言运行时异常中启用了 System.IO.FileNotFound 异常。

我收到此运行时错误。

System.IO.FileNotFoundException:'无法加载文件或程序集'DevExpress.Persistent.BaseImpl.EF.v20.2,Version=20.2.5.0,Culture=neutral,PublicKeyToken=b88d1754d700e49a'或其依赖项之一。该系统找不到指定的文件。'

调用堆栈是

mscorlib.dll!System.Reflection.RuntimeAssembly.LoadWithPartialNameInternal(System.Reflection.AssemblyName an, System.Security.Policy.Evidence securityEvidence, ref System.Threading.StackCrawlMark stackMark)
mscorlib.dll!System.Reflection.Assembly.LoadWithPartialName(string partialName)
DevExpress.Data.v21.1.dll!DevExpress.Data.Utils.Helpers.LoadWithPartialName(string partialName)
DevExpress.Data.v21.1.dll!DevExpress.Data.Utils.AssemblyCache.LoadWithPartialName(string partialName)
DevExpress.Data.v21.1.dll!DevExpress.Utils.Design.DXAssemblyResolverEx.OnAssemblyResolve(object sender, System.ResolveEventArgs e)
mscorlib.dll!System.AppDomain.OnAssemblyResolveEvent(System.Reflection.RuntimeAssembly assembly, string assemblyFullName)
[Native to Managed Transition]
[Managed to Native Transition]
mscorlib.dll!System.RuntimeTypeHandle.GetTypeByName(string name, bool throwOnError, bool ignoreCase, bool reflectionOnly, ref System.Threading.StackCrawlMark stackMark, System.IntPtr pPrivHostBinder, bool loadTypeFromPartialName)
mscorlib.dll!System.Type.GetType(string typeName, bool throwOnError)
EntityFramework.dll!System.Data.Entity.Infrastructure.DependencyResolution.ClrTypeAnnotationSerializer.Deserialize(string name, string value)
EntityFramework.dll!System.Data.Entity.Core.SchemaObjectModel.SchemaElement.CreateMetadataPropertyFromXmlAttribute(string xmlNamespaceUri, string attributeName, string value)
EntityFramework.dll!System.Data.Entity.Core.SchemaObjectModel.SchemaElement.AddOtherContent(System.Xml.XmlReader reader)
EntityFramework.dll!System.Data.Entity.Core.SchemaObjectModel.SchemaElement.ParseAttribute(System.Xml.XmlReader reader)
EntityFramework.dll!System.Data.Entity.Core.SchemaObjectModel.SchemaElement.Parse(System.Xml.XmlReader reader)
EntityFramework.dll!System.Data.Entity.Core.SchemaObjectModel.Schema.HandleEntityTypeElement(System.Xml.XmlReader reader)
EntityFramework.dll!System.Data.Entity.Core.SchemaObjectModel.Schema.HandleElement(System.Xml.XmlReader reader)
EntityFramework.dll!System.Data.Entity.Core.SchemaObjectModel.SchemaElement.ParseElement(System.Xml.XmlReader reader)
EntityFramework.dll!System.Data.Entity.Core.SchemaObjectModel.SchemaElement.Parse(System.Xml.XmlReader reader)
EntityFramework.dll!System.Data.Entity.Core.SchemaObjectModel.Schema.HandleTopLevelSchemaElement(System.Xml.XmlReader reader)
EntityFramework.dll!System.Data.Entity.Core.SchemaObjectModel.Schema.InternalParse(System.Xml.XmlReader sourceReader, string sourceLocation)
EntityFramework.dll!System.Data.Entity.Core.SchemaObjectModel.Schema.Parse(System.Xml.XmlReader sourceReader, string sourceLocation)
EntityFramework.dll!System.Data.Entity.Core.SchemaObjectModel.SchemaManager.ParseAndValidate(System.Collections.Generic.IEnumerable<System.Xml.XmlReader> xmlReaders, System.Collections.Generic.IEnumerable<string> sourceFilePaths, System.Data.Entity.Core.SchemaObjectModel.SchemaDataModelOption dataModel, System.Data.Entity.Core.SchemaObjectModel.AttributeValueNotification providerNotification, System.Data.Entity.Core.SchemaObjectModel.AttributeValueNotification providerManifestTokenNotification, System.Data.Entity.Core.SchemaObjectModel.ProviderManifestNeeded providerManifestNeeded, out System.Collections.Generic.IList<System.Data.Entity.Core.SchemaObjectModel.Schema> schemaCollection)
EntityFramework.dll!System.Data.Entity.Core.SchemaObjectModel.SchemaManager.ParseAndValidate(System.Collections.Generic.IEnumerable<System.Xml.XmlReader> xmlReaders, System.Collections.Generic.IEnumerable<string> sourceFilePaths, System.Data.Entity.Core.SchemaObjectModel.SchemaDataModelOption dataModel, System.Data.Entity.Core.Common.DbProviderManifest providerManifest, out System.Collections.Generic.IList<System.Data.Entity.Core.SchemaObjectModel.Schema> schemaCollection)
EntityFramework.dll!System.Data.Entity.Core.Metadata.Edm.EdmItemCollection.LoadItems(System.Collections.Generic.IEnumerable<System.Xml.XmlReader> xmlReaders, System.Collections.Generic.IEnumerable<string> sourceFilePaths, System.Data.Entity.Core.SchemaObjectModel.SchemaDataModelOption dataModelOption, System.Data.Entity.Core.Common.DbProviderManifest providerManifest, System.Data.Entity.Core.Metadata.Edm.ItemCollection itemCollection, bool throwOnError)
EntityFramework.dll!System.Data.Entity.Core.Metadata.Edm.EdmItemCollection.Init(System.Collections.Generic.IEnumerable<System.Xml.XmlReader> xmlReaders, System.Collections.Generic.IEnumerable<string> filePaths, bool throwOnError)
EntityFramework.dll!System.Data.Entity.Core.Metadata.Edm.EdmItemCollection.EdmItemCollection(System.Collections.Generic.IEnumerable<System.Xml.XmlReader> xmlReaders)
EntityFramework.dll!System.Data.Entity.Utilities.XDocumentExtensions.GetStorageMappingItemCollection(System.Xml.Linq.XDocument model, out System.Data.Entity.Infrastructure.DbProviderInfo providerInfo)
EntityFramework.dll!System.Data.Entity.Migrations.Infrastructure.EdmModelDiffer.Diff(System.Xml.Linq.XDocument sourceModel, System.Xml.Linq.XDocument targetModel, System.Lazy<System.Data.Entity.Migrations.Infrastructure.ModificationCommandTreeGenerator> modificationCommandTreeGenerator, System.Data.Entity.Migrations.Sql.MigrationSqlGenerator migrationSqlGenerator, string sourceModelVersion, string targetModelVersion)
EntityFramework.dll!System.Data.Entity.Internal.InternalContext.ModelMatches(System.Data.Entity.Migrations.Infrastructure.VersionedModel model)
EntityFramework.dll!System.Data.Entity.Internal.ModelCompatibilityChecker.CompatibleWithModel(System.Data.Entity.Internal.InternalContext internalContext, System.Data.Entity.Internal.ModelHashCalculator modelHashCalculator, bool throwIfNoMetadata, System.Data.Entity.Internal.DatabaseExistenceState existenceState)
EntityFramework.dll!System.Data.Entity.Internal.InternalContext.CompatibleWithModel(bool throwIfNoMetadata, System.Data.Entity.Internal.DatabaseExistenceState existenceState)
EntityFramework.dll!System.Data.Entity.Database.CompatibleWithModel(bool throwIfNoMetadata, System.Data.Entity.Internal.DatabaseExistenceState existenceState)
EntityFramework.dll!System.Data.Entity.Database.CompatibleWithModel(bool throwIfNoMetadata)
VIV.MyApp2.Win.exe!MyApp2.Win.Program.CheckMigrationVersionAndAskToUpgradeIfNeeded() Line 98
    at D:\dev\Viv.MyApp2\MyApp2.Win\Program.cs(98)
VIV.MyApp2.Win.exe!MyApp2.Win.Program.Main() Line 45
    at D:\dev\Viv.MyApp2\MyApp2.Win\Program.cs(45)

我之前遇到过这个错误,并在这里向 Dev Express报告,但问题消失了。

源代码是

    private static bool CheckMigrationVersionAndAskToUpgradeIfNeeded()
    {
        try
        {
            using (var db = new MigrationDbContext())
            {
                var compatible = db.Database.CompatibleWithModel(false);
                if (!compatible) compatible = RunMigrationsIfPresent(db);
                return compatible;
            }
        }
        catch (Exception ex)
        {
            var s = string.Format("Problem in MigrateIfNeeded \r\n" + ex);
            MessageBox.Show(s);
            return false;
        }
    }

实体框架是 v6.4.4

目标框架是 .Net Framework 4.7.2

错误线

从调用堆栈看来,GetTypeByName 正在解析为错误的类型。我该如何解决?

我不确定这个问题是否相关

标签: c#visual-studiowinformsentity-frameworkreflection

解决方案


推荐阅读