Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"An entry with the same key already exists" appears when compiled under .NET 4

I am trying to upgrade an ASP.NET application to .NET 4, but one page on my site contains an exception:

Argument Exception: an entry with the same key already exists".

What is different about ASP.NET 4 that might cause this problem?

enter image description here

One Solution

Not sure why but setting clientIDMode="Predictable" rather than Static seems to have avoided this exception message.

like image 328
Tom Avatar asked Dec 29 '10 12:12

Tom


1 Answers

I had the same issue and fixed it.

I went through my entire ASPX page and found ASP.NET control that had the same ID as another.

I also tested this fix, and found that any control that conflicts with another control on the page will cause this error.

<asp:Label ID="FailureText" runat="server" EnableViewState="False" ClientIDMode="Static" />

<asp:Label ID="FailureText" runat="server" EnableViewState="False" ClientIDMode="Static" />

It happens when you Copy/Paste elements on the same page.

like image 118
Ravi Ram Avatar answered Oct 12 '22 01:10

Ravi Ram