1

I am migrating from Visual Studio 2017 to Visual Studio 2022 and got an EF error about "Value cannot be null. Parameter name: type", so I updated my Entity Framework 6.2.0 to EF 6.4.4. Now I get this error that the ConceptualModels tag does not match (when trying to update my database). How can I check my ConceptualModels and fix this issue?

(CodeFirst project)

Error:

  at System.Xml.XmlTextReaderImpl.ParseElementContent()
   at System.Xml.Linq.XContainer.ReadContentFrom(XmlReader r)
   at System.Xml.Linq.XContainer.ReadContentFrom(XmlReader r, LoadOptions o)
   at System.Xml.Linq.XDocument.Load(XmlReader reader, LoadOptions options)
   at System.Xml.Linq.XDocument.Load(Stream stream, LoadOptions options)
   at System.Data.Entity.Migrations.Edm.ModelCompressor.Decompress(Byte[] bytes)
   at System.Data.Entity.Migrations.DbMigration.GetModel(Func`2 modelAccessor)
   at System.Data.Entity.Migrations.DbMigrator.ApplyMigration(DbMigration migration, DbMigration lastMigration)
   at System.Data.Entity.Migrations.Infrastructure.MigratorLoggingDecorator.ApplyMigration(DbMigration migration, DbMigration lastMigration)
   at System.Data.Entity.Migrations.DbMigrator.Upgrade(IEnumerable`1 pendingMigrations, String targetMigrationId, String lastMigrationId)
   at System.Data.Entity.Migrations.Infrastructure.MigratorLoggingDecorator.Upgrade(IEnumerable`1 pendingMigrations, String targetMigrationId, String lastMigrationId)
   at System.Data.Entity.Migrations.DbMigrator.UpdateInternal(String targetMigration)
   at System.Data.Entity.Migrations.DbMigrator.EnsureDatabaseExists(Action mustSucceedToKeepDatabase)
   at System.Data.Entity.Migrations.DbMigrator.Update(String targetMigration)
   at System.Data.Entity.Infrastructure.Design.Executor.Update.<>c__DisplayClass0_0.<.ctor>b__0()
   at System.Data.Entity.Infrastructure.Design.Executor.OperationBase.Execute(Action action)
The 'ConceptualModels' start tag on line 4 position 6 does not match the end tag of 'ConceptualModessociationSet'. Line 1747, position 7.

enter image description here

My DB context:

namespace GMM.Repository.Context
{
    public class GMMDbContext : IdentityDbContext<ApplicationUser, AppRole, string, IdentityUserLogin, IdentityUserRole, IdentityUserClaim>
    {
        public static string ConnectionString { get; set; }
        static GMMDbContext()
        {
#if DEBUG
            ConnectionString = "GMMConnection";
#endif
        }
        public static GMMDbContext Create()
        {
            return new GMMDbContext();
        }

        public GMMDbContext()
            : base(ConnectionString)             
        {
            Database.SetInitializer(new MigrateDatabaseToLatestVersion<GMMDbContext, GMM.Repository.Migrations.Configuration>());
            DbInterception.Add(new FtsInterceptor());
        }

        #region AccessControl
        public IDbSet<GroupRole> GroupRoles { get; set; }
        public IDbSet<RoleGroup> RoleGroups { get; set; }
        public IDbSet<UserRoleGroup> UserRoleGroups { get; set; }
        #endregion

        #region BaseInformation
        public IDbSet<Department> Departments { get; set; }
        #endregion

 

        #region General
        public IDbSet<Location> Locations { get; set; }

        public IDbSet<Setting> Settings { get; set; }
  
        #endregion

     



        public int SaveChanges(string currentUserIp)
        {
            AddTimestamps(currentUserIp);
            return base.SaveChanges();
        }

        public Task<int> SaveChangesAsync(string userIp)
        {
            AddTimestamps(userIp);
            return base.SaveChangesAsync();
        }

        public override int SaveChanges()
        {
            AddTimestamps();
            return base.SaveChanges();
        }

        private void AddTimestamps(string currentUserId, string currentUserIp)
        {
            if (currentUserId == null)
            {
                throw new NullReferenceException("CurrentUserId");
            }

            var entities = ChangeTracker.Entries().Where(x => x.Entity is IBaseEntity && (x.State == EntityState.Added || x.State == EntityState.Modified));
            foreach (var entity in entities)
            {
                if (entity.State == EntityState.Added)
                {
                    ((BaseGuidEntity)entity.Entity).DateCreated = DateTime.Now;
                    ((BaseGuidEntity)entity.Entity).CreatedBy_Id = currentUserId;
                    ((BaseGuidEntity)entity.Entity).CreatedByIp = currentUserIp;
                }

                ((BaseGuidEntity)entity.Entity).DateModified = DateTime.Now;
                ((BaseGuidEntity)entity.Entity).ModifiedBy_Id = currentUserId;
                ((BaseGuidEntity)entity.Entity).ModifiedByIp = currentUserIp;
            }
        }

        private void AddTimestamps()
        {
            var entities = ChangeTracker.Entries().Where(x => x.Entity is IBaseEntity && (x.State == EntityState.Added || x.State == EntityState.Modified));
            foreach (var entity in entities)
            {
                if (entity.State == EntityState.Added)
                {
                    ((BaseGuidEntity)entity.Entity).DateCreated = DateTime.UtcNow;

                }
                ((BaseGuidEntity)entity.Entity).DateModified = DateTime.UtcNow;
            }
        }

        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            modelBuilder.Conventions.Remove<PluralizingTableNameConvention>();

            #region Message
            modelBuilder.Configurations.Add(new PrivacyConfig());
            modelBuilder.Configurations.Add(new ResultConfig());
            modelBuilder.Configurations.Add(new SubjectConfig());
            modelBuilder.Configurations.Add(new PriorityConfig());
            modelBuilder.Configurations.Add(new CategoryConfig());
            modelBuilder.Configurations.Add(new MessageConfig());
            modelBuilder.Configurations.Add(new MessageFeedbackConfig());
            modelBuilder.Configurations.Add(new ReferConfig());
            #endregion

            base.OnModelCreating(modelBuilder);
        }
    }
}

My model diagram: My Model Diagram

janw
  • 8,758
  • 11
  • 40
  • 62
  • Trace back changes in the EDMX file. Somewhere in the process it got corrupted. – Gert Arnold Dec 12 '22 at 20:13
  • it didn't because the same source worked on last EF v5.0.0 and Visual Studio 2017. but in EF v6.4.4 and Visual Studio 2022 not. actually, I add a new Context by EF v6.4.4 with the same Model (Last One) and Just Copy Paste it old model, then My problem was Fixed. But steal don't know what is the problem ! – MohamadReza Alamdar Dec 17 '22 at 12:39

1 Answers1

0

I just removed hole DBContex from the project and added new Context by using EF v6.4.4 and Visual Studio 2022 then copy paste my whole old model structure. and my problem was solved. It seems Visual Studio 2017 XML parser or creator is not the same as Visual Studio 2017. so when I create my old XML structure model by vs2022, the problem solved