Entity Framework exception: the index was outside the bounds of the array. "

OK, I have a problem with Entity Framework. It worked for me, but now some more objects have been added to the model, and now I get the above error. For debugging purposes, I created a test form with a grid control to populate from a collection of Project objects. FYI, I use a GUID for my primary keys. I have only one bit of code:

Public Class TestForm
Private Sub TestForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    Me.ProjectBindingSource.DataSource = My.Application.Context.Projects
End Sub
End Class

Here is the detail of the exception:

Internal exception: {"The index was outside the array".} Source: "System.Data.Entity"

Error System.Data.EntityCommandCompilationException was unhandled Message = "An error occurred while preparing the definition of the command. For more details, see Internal Exception." Source = "System.Data.Entity" Stack Trace: at System.Data.EntityClient.EntityCommandDefinition..ctor (DbProviderFactory storeProviderFactory, DbCommandTree commandTree) in System.Data.EntityClient.EntityProviderServices.CreateCommandDefinition (DbProviderFactory storeProviderFactory, DbCommandTree commandTree) in the System. Data.EntityClient.EntityProviderServices.CreateDbCommandDefinition (DbProviderManifest providerManifest, DbCommandTree commandTree) in System.Data.Common.DbProviderServices.CreateCommandDefinition (DbCommandTree commandTreebject.latebject.rtbeclate.tececlate.tececlate.tececlatejectata_tecbecl.Docjectlatabject01latebteclocation_ternecdbeclocation_trbeclocationPrepare (ObjectContext context, DbQueryCommandTree tree, type ElementType, MergeOption MergeOption, Span range) in System.Data.Objects.EntitySqlQueryState.GetExecutionPlan (Zero1 forMergeOption) at System.Data.Objects.ObjectQuery1.GetResults (Nullable1 forMergeOption) at System.Data.Objects.ObjectQuery1.GetIListSourceListInternal () in System.Data.Objects.ObjectQuery.System.ComponentModel.IListSource.GetList () in System.Windows.Forms.ListBindingHelper.GetList (list of objects) in System.Windows.Forms.ListBindingHelper.GetList Object , String dataMember) in System.Windows.Forms.BindingSource.ResetList () in System.Windows.Forms.BindingSource.set_DataSource (object value) in TestApp.TestForm.TestForm_Load (object sender, EventArgs e) in C: \ Users \ JoshPeltier .TFEARTH \ Documents \ Visual Studio 2008 \ Projects \ TestApp \ TestApp \ Forms \ TestForm.vb: line 3 in System.EventHandler.Invoke (object sender, EventArgs e) in System.Windows.Forms.Form.OnLoad (EventArgs e) in System.Windows.Forms.Form.OnCreateControl () in System.Windows.Forms.Control.CreateControl (Boolean fIgnoreVisible) in System.Windows.Forms.Control.CreateControl () in System.Windows.Forms.Control.WmShowWindow (Message & m) in System.Windows.Forms.Control.WndProc (Message & m) in System. Windows.Forms.ScrollableControl.WndProc (Message & m) in System.Windows.Forms.ContainerControl.WndProc (Message & m) in System.Windows.Forms.Form.WmShowWindow (Message & m) in System.Windows.Forms.Form .WndProc (Message & m) in System.Windows.Forms.Control.ControlNativeWindow.OnMessage (Message & m) in System.Windows.Forms.Control.ControlNativeWindow.WndProc (Message & m) in System.Windows.Forms.NativeWindow. DebuggableCallback (IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam) in System.Windows.Forms.SafeNativeMethods.ShowWindow (HandleRef hWnd,Int32 nCmdShow) in System.Windows.Forms.Control.SetVisibleCore (boolean) in System.Windows.Forms.Form.SetVisibleCore (boolean) in System.Windows.Forms.Control.set_Visible (boolean) in System.Windows. Forms.Application.ThreadContext.RunMessageLoopInner (Int32 reason, ApplicationContext context) in System.Windows.Forms.Application.ThreadContext.RunMessageLoop (Int32 reason, ApplicationContext context) in System.Windows.Forms.Application.Run (ApplicationContext context) in Microsoft. VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun () in Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel () in Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run ()MyApplication.Main (String [] Args) in 17d14f5c-a337-4978-8281-53493378c1071.vb: line 81 in System.AppDomain._nExecuteAssembly (assembly assembly, String [] args) in System.AppDomain.ExecuteAssembly (String assemblyFile, Evidence assemblySecurity, String [] args) in Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly () in System.Threading.ThreadHelper.ThreadStart_Context (object state) in System.Threading.ExecutionContext.Run (ExecutionContext executeContext, object callback ContextCalltext, callback state) in System.Threading.ThreadHelper.ThreadStart () InnerException: System.IndexOutOfRangeException Message = "The index was outside the array." Source = "System.Data.Entity" Stack Traces: in System.Data.Mapping.ViewGeneration.Structures.CellQuery.CreateFieldAlignedCellQueries (CellQuery otherQuery, MemberPathMapBase projectedSlotMap, CellQuery & newMainQuery, CellQuery & newOtherQuery) in System.Data.Mapping.ViewGeneration.CellNormalizer.AlumeFields IE1 cells, MemberPathMapBase projectedSlotMap, ViewTarget viewTarget) at System.Data.Mapping.ViewGeneration.CellNormalizer.CreateLeftCellWrappers(IEnumerable1 extentCells, ViewTarget viewTarget) in System.Data.Mapping.ViewGeneration.CellNormalizer..ctor (EntitySetBase size, IEnumerable 1 extentCells, SchemaContext schemaContext, CqlIdentifiers identifiers, ConfigViewGenerator config, MemberDomainMap queryDomainMap, MemberDomainMap updateDomainMap, StorageEntityContainerMapping entityContainerMapping, MetadataWorkspace workspace) at System.Data.Mapping.ViewGeneration.ViewGenerator.GetCellNormalizer(EntitySetBase extent, SchemaContext schemaContext, CqlIdentifiers identifiers) at System.Data.Mapping.ViewGeneration.ViewGenerator.GenerateViewsForExtent(SchemaContext schemaContext, EntitySetBase extent, CqlIdentifiers identifiers, KeyToListMap2 views) in System.Data.Mapping.ViewGeneration.ViewGenerator.GenerateViewsForSchemaContext (SchemaContext schemaContext, CqlIdentifiers identifiers, KeyToListMap 2 views) at System.Data.Mapping.ViewGeneration.ViewGenerator.GenerateAllViews(KeyToListMap2 representation, CqlIdentifiers) in System.Data.Mapping.ViewGeneration.ViewGenerator.GenerateViewsForSchemaCells (List 1 cells, MetadataWorkspace workSpace, ConfigViewGenerator config, CqlIdentifiers identifiers, StorageEntityContainerMapping containerMapping) at System.Data.Mapping.ViewGeneration.ViewGenerator.GenerateViewsForSchema(StorageEntityContainerMapping containerMapping, MetadataWorkspace workSpace, ConfigViewGenerator config) at System.Data.Mapping.StorageMappingItemCollection.ViewDictionary.SerializedGenerateViews(EntityContainer container, Dictionary2 resultDictionary) in System.Data.Mapping.StorageMappingItemCollection.ViewDictionary.SerializedGetGeneratedViews (EntityContainer container) in System.Data.Commonoizer.ultilsultult 2.<>c__DisplayClass2.<Evaluate>b__0() at System.Data.Common.Utils.Memoizer. GetValue () in System.Data.Common.Utils.Memoizer2.Evaluate(TArg arg) at System.Data.Mapping.StorageMappingItemCollection.ViewDictionary.GetGeneratedView(EntitySetBase extent, MetadataWorkspace workspace, StorageMappingItemCollection storageMappingItemCollection) at System.Data.Metadata.Edm.MetadataWorkspace.GetGeneratedView(EntitySetBase extent) at System.Data.Query.PlanCompiler.PreProcessor.ExpandView(Node node, ScanTableOp scanTableOp, IsOfOp& typeFilter) at System.Data.Query.PlanCompiler.PreProcessor.ProcessScanTable(Node scanTableNode, ScanTableOp scanTableOp, IsOfOp& typeFilter) at System.Data.Query.PlanCompiler.PreProcessor.Visit(ScanTableOp op, Node n) at System.Data.Query.InternalTrees.ScanTableOp.Accept[TResultType](BasicOpVisitorOfT1 v, Node n) in System.Data.Query.InternalTrees.BasicOpVisitorOfT 1.VisitNode(Node n) at System.Data.Query.PlanCompiler.PreProcessor.VisitChildren(Node n) at System.Data.Query.PlanCompiler.PreProcessor.VisitRelOpDefault(RelOp op, Node n) at System.Data.Query.PlanCompiler.PreProcessor.Visit(ProjectOp op, Node n) at System.Data.Query.InternalTrees.ProjectOp.Accept[TResultType](BasicOpVisitorOfT1 v, Node n) in System.Data.Query.InternalTrees.BasicOpVisitorOfT 1.VisitNode(Node n) at System.Data.Query.PlanCompiler.PreProcessor.VisitChildren(Node n) at System.Data.Query.InternalTrees.BasicOpVisitorOfNode.VisitDefault(Node n) at System.Data.Query.InternalTrees.BasicOpVisitorOfNode.VisitPhysicalOpDefault(PhysicalOp op, Node n) at System.Data.Query.InternalTrees.BasicOpVisitorOfT1.Visit (PhysicalProjectOp op, Node n) in System.Data.Query.InternalTrees .PhysicalProjectOp.Accept [TResultType] (BasicOpVisitorOfT 1 v, Node n) at System.Data.Query.InternalTrees.BasicOpVisitorOfT1.VisitNode (Node n) in System.Data.Query.PlanCompiler.PreProcessor.Process () in System.Data.Query.PlanCompiler.PreProcessor.Process (PlanCompilerfoPreformProp in System.Data.Query.PlanCompiler.PlanCompiler.Compile (List 1& providerCommands, ColumnMap& resultColumnMap, Int32& columnCount, Set1 & entitySets) in System.Data.Query.PlanCompiler.PlanCompiler.Compile (DbCommandTree ctree, List1& providerCommands, ColumnMap& resultColumnMap, Int32& columnCount, Set 1 & entitySets) in System.Data.EntityClient.EntityCommandDefinition..ctor (DbProviderFactory storeProviderFactory, DbCommandTree commandTree) InnerException:

Any ideas?

+3
source share
2 answers

they had the same problem on msdn forum ( http://social.msdn.microsoft.com/Forums/en-US/adodotnetentityframework/thread/fa618214-ad3d-42fc-8506-21d539aa2cb3 )

check the answer there, maybe some additional material in your model that should not be. can you publish edmx file?

+1
source

I just happened to me.

, !

, .edmx :

<AssociationSetMapping Name="Table1Table2" TypeName="MyModel.Table1Table2" StoreEntitySet="Table2">
    <EndProperty Name="Table1">
        <ScalarProperty Name="Table1Key" ColumnName="Table1Key" /></EndProperty>
    <EndProperty Name="Table2">
        <ScalarProperty Name="Table2Key" ColumnName="Table2Key" />
        <ScalarProperty Name="Table2OtherColumn" ColumnName="Table2OtherColumn" />
</EndProperty></AssociationSetMapping>

2 :

<EntityType Name="Table2">
    <Key>
        <PropertyRef Name="Table2Key" />
    </Key>
    <Property Name="Table2Key" Type="int" Nullable="false" />
    <Property Name="Table2OtherColumn" Type="int" Nullable="false" />
    ...other properties...
</EntityType>

, Table2OtherColumn EndProperty, . EndProperty .

, Entity Framework 4 (Visual Studio 2010) . , , / , VS 2010 Express ( !) .

+1

Source: https://habr.com/ru/post/1706066/


All Articles