There's no bug in the code that you posted. The problem is either of conceptual kind or lies in the code that calls
UpdateProduct(..)
.
In this line:
productUpdateDictionary.Add( products[i].code, new ProductUpdate { Index = i, ProductCode = products[i].code } );
your code is populating a Dictionary. A Dictionary only ever allows unique keys to be added. One or more
Product
s in the method-argument
List<Product> products
have identical
code
s and that's the cause of the exception here.
Edit: <> troubles