Search code examples
c#.netormnpoco

NPOCO 'System.ArgumentException: An item with the same key has already been added.'


I am attempting to use NPoco to Query a stored procedure and retrieve a list of Phone numbers. Below is my code, but my issue is every time dc.QueryStoredProcedure is called I receive an error 'System.ArgumentException: An item with the same key has already been added.'

I have executed the sprocs without fail. I have attempted Google but I'm unable to find anything regarding Npoco and this error message. I'm stumped at this point. I've checked over PhoneNumber object just to be sure there was nothing duplicated.

Any pointers would be greatly appreciated! Thank you.

    private List<PhoneNumber> GetPhoneNumberFromDL(int? MemberID, int? MemberIDPhoneNumber)
    {
        var TheList = new List<PhoneNumber>();

        var parameters = new[] 
            {
                new Parameter("MemberID", MemberID),
                new Parameter("MemberIDPhoneNumber", MemberIDPhoneNumber)

            };


       using (var dc = this._DataProvider.AlphaDatabase())

            {
               var results = dc.QueryStoredProcedure<PhoneNumber>("phone_num_GET", parameters);

               TheList.AddRange(results);

               return TheList;
            }
    }

Solution

  • I found the issue. I went back over my PhoneNumber object, which I thought I had looked at previously, but missed a duplicate property. It appears there was an issue with case-sensitivity and the property name 6 years back. I removed the duplicate and it's working fine.