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 790353
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T21:40:07+00:00 2026-05-14T21:40:07+00:00

In trying to setup a unit test for inserting an item into an SQL

  • 0

In trying to setup a unit test for inserting an item into an SQL Server Express (2008) database using C# Linq I’ve encountered an error that is causing me some trouble. The Linq code is built using Visual Studio 2008.

The exception is thrown on a system running Windows XP SP2. The Linq works fine and the record is inserted appropriately on a system running Windows 7 Home Premium (64-bit).

I’ve dropped and re-created the database on the XP system. I’ve dropped and re-created the DAL and corresponding DBML on the XP system.

Other tables with unit tests for inserts to the same database work just fine.

Inserting a record into the table using a simple insert statement in SQL Server Management Studio works appropriately.

What should I look at to find the source of the problem? What should be done to resolve the problem?

Any insight as to what the error message is really trying to say would be greatly appreciated.

Error Message

System.IndexOutOfRangeException : Index was outside the bounds of the array.

Stack Trace

at 

System.Data.Linq.IdentityManager.StandardIdentityManager.MultiKeyManager`3.TryCreateKeyFromValues(Object[] values, MultiKey`2& k)
at System.Data.Linq.IdentityManager.StandardIdentityManager.IdentityCache`2.Find(Object[] keyValues)
at System.Data.Linq.IdentityManager.StandardIdentityManager.Find(MetaType type, Object[] keyValues)
at System.Data.Linq.CommonDataServices.GetCachedObject(MetaType type, Object[] keyValues)
at System.Data.Linq.ChangeProcessor.GetOtherItem(MetaAssociation assoc, Object instance)
at System.Data.Linq.ChangeProcessor.BuildEdgeMaps()
at System.Data.Linq.ChangeProcessor.SubmitChanges(ConflictMode failureMode)
at System.Data.Linq.DataContext.SubmitChanges(ConflictMode failureMode)
at System.Data.Linq.DataContext.SubmitChanges()
at nUnit.DAL.FacilityTests.AddFacility2() in C:\SVN\SVNRevenue360\Branches\Dev\Code\ProviderAdvantage\nUnit.CoreTests\Tests\DAL\FacilityTests.cs:line 50

Insert Code

        [Test]
    public void AddFacility2() {
        string facilityname = "Test Facility";
        try {
            using (PA.Database.Revenue360DB db = new PA.Database.Revenue360DB(PA.DAL.DataAccess.ConnectionString)) {
                db.Log = Console.Out;
                PA.Database.Facility facility = new PA.Database.Facility();
                facility.id = Guid.NewGuid();
                facility.Name = facilityname;
                facility.Street1 = "";
                facility.Street2 = "";
                facility.Street3 = "";
                facility.City = "";
                facility.State = "";
                facility.Zip = "";
                facility.Description = "";

                db.Facilities.InsertOnSubmit(facility);
                db.SubmitChanges();  // line 50
            }
        } catch (Exception ex) {
            Console.WriteLine(ex.GetType().FullName + ":  " + ex.Message);
            Console.WriteLine(ex.InnerException == null ? 
                "No inner exception" :
                ex.InnerException.GetType().FullName + ":  " + ex.InnerException.Message);
            throw;
        }
    }

I’ve looked at the following SO questions without insight as to what is causing this particular issue.

https://stackoverflow.com/questions/1087172/why-am-i-getting-index-was-outside-the-bounds-of-the-array
IndexOutOfRangeException on Queryable.Single
Strange LINQ Exception (Index out of bounds)

  • 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-14T21:40:07+00:00Added an answer on May 14, 2026 at 9:40 pm

    Take a look at this link.

    Here are a few excerpts:

    A common cause of this error is
    associations pointing in the wrong
    direction. (Something that is
    extremely easy to do if editing the
    model by hand, partly because the
    association arrow pointer is in the
    opposite end of where it would appear
    in an ER diagram)

    and

    I was having the same problem and it
    was due to the fact my primary key was
    two columns instead of the traditional
    one. (both guids). When I added a
    third column that was the sole primary
    key column, it worked.

    UPDATE: Did some more poking around and found this SO post. Looks like it might have something to do with your DBML…

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

Sidebar

Ask A Question

Stats

  • Questions 427k
  • Answers 427k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer I was at the Stackoverflow DevDays event in London last… May 15, 2026 at 12:52 pm
  • Editorial Team
    Editorial Team added an answer Try the <include> XML layout directive. May 15, 2026 at 12:52 pm
  • Editorial Team
    Editorial Team added an answer Thats basically how closures and loops work in c#. Take… May 15, 2026 at 12:52 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.