Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6922509
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T10:24:55+00:00 2026-05-27T10:24:55+00:00

I have a custom initializer setup as follows: public class PromptIfChangesNeededDBInitializer : IDatabaseInitializer<MeyerREContext> {

  • 0

I have a custom initializer setup as follows:

public class PromptIfChangesNeededDBInitializer : IDatabaseInitializer<MeyerREContext>
{

    public PromptIfChangesNeededDBInitializer()
    {  // This constructor is called properly

    }

    #region IDatabaseInitializer<TContext> Members


    public void InitializeDatabase(MeyerREContext context)
    { // This is never called

       ... Code that checks existence and seeds etc

    }

 }

Here is my DbContext class

public class MeyerREContext : DbContext
{
    static MeyerREContext()
    {
        Database.SetInitializer(new PromptIfChangesNeededDBInitializer());
    }

    public DbSet<Address> Addresses { get; set; }
    ... More DbSet property definitions


protected override void OnModelCreating(DbModelBuilder modelBuilder)
    {

       modelBuilder.Configurations.Add(new AddressMap());
      ... More Configurations 

    }

}

This is the first call to the context

City city = dbNew.Cities.Where(e=>e.CityName=="Foley").FirstOrDefault();

The constructor of the Initializer is called properly as confirmed by a breakpoint, the OnModelCreating runs properly as confirmed by a breakpoint, but after the OnModelCreating is completed the InitializeDatabase is never called…

I removed the Database.SetInitializer(new PromptIfChangesNeededDBInitializer()) call from the ctor of the DBContext into the ctor of the calling class BEFORE any calls to the context and I get slightly different behavior now:

public class CreateData
{

    private VFPModelContainer db = new VFPModelContainer();
    private MeyerREContext dbNew;

    public CreateData()
    {
        Database.SetInitializer(new PromptIfChangesNeededDBInitializer<MeyerREContext>());

        dbNew = new MeyerREContext();
        dbNew.Database.Initialize(force: true);   NUll Exception here now...

    }

A null exception is geenrated now in the EF Framework code:

Here is the exception detail:

System.NullReferenceException occurred
Message=Object reference not set to an instance of an object.
Source=EntityFramework
StackTrace:
   at    
    System.Data.Entity.ModelConfiguration.Configuration.Properties.Navigation.NavigationPropertyConfiguration.ValidateConsistency(NavigationPropertyConfiguration navigationPropertyConfiguration)

InnerException:

It looks like the exception is happening in one of the EntityTypeConfiguration calls, but the exception is being swallowed somehow ? How can I figure out which call it is ? There are around 100 entities in this model…

How can I get more info than is shown in the Intellitrace ?

How to get more info about what went wrong inside EF ? I need to know which navigational property is having problems… I think the problem is that EF is creating background worker threads to create & validate the model, but I don’t understand why the exception is soooo vague ??

Any ideas ?

Thanks
Greg

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T10:24:55+00:00Added an answer on May 27, 2026 at 10:24 am

    had to install Reflector and Decompile the EF Assembly to find out what the problem was:

    This is the line that causes the problem…

    private void ValidateConsistency(NavigationPropertyConfiguration navigationPropertyConfiguration)
    {
      if ((navigationPropertyConfiguration.InverseEndKind.HasValue && this.EndKind.HasValue) && (navigationPropertyConfiguration.InverseEndKind != this.EndKind))
      {
        throw System.Data.Entity.ModelConfiguration.Resources.Error.ConflictingMultiplicities(this.NavigationProperty.Name, this.NavigationProperty.ReflectedType);
      }
      if ((navigationPropertyConfiguration.EndKind.HasValue && this.InverseEndKind.HasValue) && (navigationPropertyConfiguration.EndKind != this.InverseEndKind))
      {
        throw System.Data.Entity.ModelConfiguration.Resources.Error.ConflictingMultiplicities(this.InverseNavigationProperty.Name, this.InverseNavigationProperty.ReflectedType);
      }
    

    In my case the InverseNavigationProperty property is null which causes and exception WHEN EF is trying to throw an exception…

    The underlying problem is that I had an inverse property relationship defined but no mapping defined for it…

    However, it was impossible to acertain which entity was causing this problem… These checks in this method should be wrapped with a try catch to avoid this problem so they can throw a more meaningful error to the end user…

    Thanks
    Greg

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a setup project with a custom installer class which launch the application
I have a structure which I create a custom constructor to initialize the members
I have a JTable with a custom TableModel called DataTableModel . I initialized the
I have a custom class, and that class has a UIButton instance variable. I
I have an Initializer class that implements the ServletContextListener interface. In its contextInitialized() method,
I have a custom control that own a property. Inside this custom control OnInit
I have a custom initializer that configures a 'cloud' storage provider (Google, AWS, Rackspace).
I have a method that returns an array of custom class objects that are
I have a custom gtk.treeview wrapper class that manages its own liststore. The class
I have custom coded several enterprise applications for mid to large organizations to use

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.