dimanche 13 juin 2021

Could not load file or assembly DevExpress.Persistent.BaseImpl.EF.v20.2

When I run my Winforms XAF Entity Framework application in VS 2019 IDE

Given I have System.IO.FileNotFound exception enabled in Common Language Runtime Exceptions.

I get this run time error.

System.IO.FileNotFoundException: 'Could not load file or assembly 'DevExpress.Persistent.BaseImpl.EF.v20.2, Version=20.2.5.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a' or one of its dependencies. The system cannot find the file specified.'

The call stack is

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)

I have encountered this error before and reported to Dev Express here but the issue went away.

The source code is

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

Entity Framework is v6.4.4

Target framework is .Net Framework 4.7.2

Error line

From the call stack it seems that GetTypeByName is resolving to the wrong type. How do I fix that?





Aucun commentaire:

Enregistrer un commentaire