Why do I get the error 'An item with the same key has already been added'?