I lost a few hours debugging this error. It surfaces when my EF Code First generates a new database. The cause was that I had recently created a class that inherited from a complex type that was used in one of my Entities. The descendant class was nowhere referenced from an Entity. How is this (for me) totally unexpected behaviour explained?
EDIT: On request the code and the stacktrace. I must correct my statement that the Exception is only thrown when the database is generated. It is thrown whenever the dbcontext is accessed for the first time. Removing the SpecializedComplexType makes the Exception disappear.
Public Class MyEntityWithComplexType
Public Sub New()
TheComplexType = New ComplexType
End Sub
'ID'
Public Property ID As Long
'NATIVE PROPERTIES'
'NAVIGATION PROPERTIES'
'COMPLEX TYPES'
Public Property TheComplexType As ComplexType
End Class
Public Class ComplexType
Public Property SomeValue As Integer
End Class
Public Class SpecializedComplexType
Inherits ComplexType
Public Property SomeAdvancedValue As Integer
End Class
System.Windows.Markup.XamlParseException was unhandled
HResult=-2146233087 Message=De aanroep van de constructor in type BridgeItConverter.MainWindow dat overeenkomt met de opgegeven bindingsbeperkingen, heeft een uitzondering veroorzaakt. regelnummer 5 en regelpositie 5. Source=PresentationFramework LineNumber=5
LinePosition=5 StackTrace: bij System.Windows.Markup.WpfXamlLoader.Load(XamlReader xamlReader, IXamlObjectWriterFactory writerFactory, Boolean skipJournaledProperties, Object rootObject, XamlObjectWriterSettings settings, Uri baseUri) bij System.Windows.Markup.WpfXamlLoader.LoadBaml(XamlReader xamlReader, Boolean skipJournaledProperties, Object rootObject, XamlAccessLevel accessLevel, Uri baseUri) bij System.Windows.Markup.XamlReader.LoadBaml(Stream stream, ParserContext parserContext, Object parent, Boolean closeStream) bij System.Windows.Application.LoadBamlStreamWithSyncInfo(Stream stream, ParserContext pc) bij System.Windows.Application.LoadComponent(Uri resourceLocator, Boolean bSkipJournaledProperties) bij System.Windows.Application.DoStartup() bij System.Windows.Application.<.ctor>b__1(Object unused) bij System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs) bij MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler) bij System.Windows.Threading.DispatcherOperation.InvokeImpl() bij System.Windows.Threading.DispatcherOperation.InvokeInSecurityContext(Object state) bij System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) bij System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) bij System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) bij System.Windows.Threading.DispatcherOperation.Invoke() bij System.Windows.Threading.Dispatcher.ProcessQueue() bij System.Windows.Threading.Dispatcher.WndProcHook(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled) bij MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled) bij MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o) bij System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs) bij MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler) bij System.Windows.Threading.Dispatcher.LegacyInvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Int32 numArgs) bij MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam) bij MS.Win32.UnsafeNativeMethods.DispatchMessage(MSG& msg) bij System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame frame) bij System.Windows.Threading.Dispatcher.PushFrame(DispatcherFrame frame) bij System.Windows.Threading.Dispatcher.Run() bij System.Windows.Application.RunDispatcher(Object ignore) bij System.Windows.Application.RunInternal(Window window) bij System.Windows.Application.Run(Window window) bij System.Windows.Application.Run() bij BridgeItConverter.Application.Main() in C:\Users\andre_000\Documents\Visual Studio 2012\Projects\BridgeItDatabase\BridgeItConverter\obj\Debug\Application.g.vb:regel 65 bij System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args) bij System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args) bij Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly() bij System.Threading.ThreadHelper.ThreadStart_Context(Object state) bij System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) bij System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) bij System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) bij System.Threading.ThreadHelper.ThreadStart() InnerException: System.ArgumentNullException HResult=-2147467261 Message=Waarde kan niet null zijn. Parameternaam: key Source=mscorlib ParamName=key StackTrace: bij System.Collections.Generic.Dictionary2.FindEntry(TKey key) bij System.Collections.Generic.Dictionary
2.TryGetValue(TKey key, TValue& value) bij System.Data.Entity.ModelConfiguration.Configuration.Mapping.SortedEntityTypeIndex.Add(EdmEntitySet entitySet, EdmEntityType entityType) bij System.Data.Entity.ModelConfiguration.Configuration.Mapping.EntityMappingService.Analyze() bij System.Data.Entity.ModelConfiguration.Configuration.Mapping.EntityMappingService.Configure() bij System.Data.Entity.ModelConfiguration.Configuration.ModelConfiguration.ConfigureEntityTypes(DbDatabaseMapping databaseMapping, DbProviderManifest providerManifest) bij System.Data.Entity.ModelConfiguration.Configuration.ModelConfiguration.Configure(DbDatabaseMapping databaseMapping, DbProviderManifest providerManifest) bij System.Data.Entity.DbModelBuilder.Build(DbProviderManifest providerManifest, DbProviderInfo providerInfo) bij System.Data.Entity.DbModelBuilder.Build(DbConnection providerConnection) bij System.Data.Entity.Internal.LazyInternalContext.CreateModel(LazyInternalContext internalContext) bij System.Data.Entity.Internal.RetryLazy2.GetValue(TInput input) bij System.Data.Entity.Internal.LazyInternalContext.InitializeContext() bij System.Data.Entity.Internal.InternalContext.Initialize() bij System.Data.Entity.Internal.InternalContext.GetEntitySetAndBaseTypeForType(Type entityType) bij System.Data.Entity.Internal.Linq.InternalSet
1.Initialize() bij System.Data.Entity.Internal.Linq.InternalSet1.get_InternalContext() bij System.Data.Entity.Infrastructure.DbQuery
1.System.Linq.IQueryable.get_Provider() bij System.Linq.Queryable.FirstOrDefault[TSource](IQueryable`1 source) bij BridgeItConverter.MainWindow.LoadData(BridgeItDB db) in C:\Users\andre_000\Documents\Visual Studio 2012\Projects\BridgeItDatabase\BridgeItConverter\MainWindow.xaml.vb:regel 233 bij BridgeItConverter.MainWindow..ctor() in C:\Users\andre_000\Documents\Visual Studio 2012\Projects\BridgeItDatabase\BridgeItConverter\MainWindow.xaml.vb:regel 32 InnerException: