Reputation: 1956
I have upgraded to Entity Framework 4.3 and get the following error:
[NullReferenceException: Object reference not set to an instance of an object.]
System.Data.Entity.ModelConfiguration.Configuration.Properties.Navigation.NavigationPropertyConfiguration.ValidateConsistency(NavigationPropertyConfiguration navigationPropertyConfiguration) +588
System.Data.Entity.ModelConfiguration.Configuration.Properties.Navigation.NavigationPropertyConfiguration.Configure(EdmNavigationProperty navigationProperty, EdmModel model, EntityTypeConfiguration entityTypeConfiguration) +122
System.Data.Entity.ModelConfiguration.Configuration.Types.EntityTypeConfiguration.ConfigureAssociations(EdmEntityType entityType, EdmModel model) +160
System.Data.Entity.ModelConfiguration.Configuration.Types.EntityTypeConfiguration.Configure(EdmEntityType entityType, EdmModel model) +102
System.Data.Entity.ModelConfiguration.Configuration.ModelConfiguration.ConfigureEntities(EdmModel model) +95
System.Data.Entity.DbModelBuilder.Build(DbProviderManifest providerManifest, DbProviderInfo providerInfo) +112
System.Data.Entity.DbModelBuilder.Build(DbConnection providerConnection) +58
System.Data.Entity.Internal.LazyInternalContext.CreateModel(LazyInternalContext internalContext) +62
System.Data.Entity.Internal.RetryLazy`2.GetValue(TInput input) +117
System.Data.Entity.Internal.LazyInternalContext.InitializeContext() +452
System.Data.Entity.Internal.InternalContext.ForceOSpaceLoadingForKnownEntityTypes() +55
System.Data.Entity.DbContext.System.Data.Entity.Infrastructure.IObjectContextAdapter.get_ObjectContext() +25
Namespace.Test.Start() in c:\Builds\6\Test\DevDeployed\Sources\Namespace.Test.Kernel\Loader.cs:97
MvcApplication.Application_Start() in c:\Builds\6\Test\DevDeployed\Sources\Namespace.Test.Kernel\Web\Global.asax.cs:48
If I build in Visual Studio the application works, but the automatic deployment website (through TFS) gives this error (as does using the MSBUILD with the command line).
There doesn't seem to be any way to get a decent error message so I am in the dark as to what is causing the problem. I don't think it is a mapping problem because I can get it to work in VS. I have tried excluding everything from the model and introducing things until a problem appears - but everything worked OK.
Thanks!
Upvotes: 0
Views: 915
Reputation: 1956
Fixed it - configurations on both sides of the association was the cause of the problem. We will move to EF 5 when it is released.
One of the guys on my team has VS Ultimate and so was able to use intellitrace to see what was going on inside EF. It turns out that one of the navigation properties was defined as Optional in one configuration and Required in another. The model is too big to have tracked this down any other way.
Visual Studio seems to construct the model in dependency order, whereas TFS/MSBUILD seems to construct it alphabetically by configuration class. This difference is why it worked on our dev machines but not on the TFS build.
You'd think by version 4.3 they might have put some debugging/exception info into the framework, or at least some way to validate the model!
Upvotes: 1
Reputation: 31610
It's a bug that should be fixed in Entity Framework 5. If you cannot move to EF5 you can fix this on your side by specifying navigation properties in both configurations for the association sides.
Upvotes: 0