Search code examples
javascriptjquerypostinternal-server-error

Resolving an Internal Server Error 500 — An item with the same key has already been added


A few days ago, I started getting an Error 500 on the POST in the code below. It's not happening to any of my teammates. The URL retrieved via logEntryUrl is valid when plugged into a browser. The call to POST works in the console. When actually invoked in the application, I'm getting the Error 500 somewhere deep in the jQuery 1.7.2 code (I would say exactly where except that it seems to depend on where I put the breakpoint):

    var logEntryUrl = getPath("Log", "SaveLogEntry", "Logs");
    $.post(logEntryUrl, $("#LogEntryForm").serialize(), function (data) {
        if (!data.IsValid) {
            $("#button-save").removeAttr('disabled');
        } else {
        refreshLogGrid();
        $("#addEditLogDiv").empty();
        $("#addEditLogDiv").dialog("close");
        $("#button-save").removeAttr('disabled');
    }
 }).fail(function (jqXHR, ajaxSettings, thrownError) {
                        console.log(jqXHR.status);
                        console.log(jqXHR.responseText);
                        console.log(thrownError);
                        refreshLogGrid();
                        $("#addEditLogDiv").empty();
                        $("#addEditLogDiv").dialog("close");
                        $("#button-save").removeAttr('disabled');
                    });

I've read through the various solutions here on Stack Exchange. I understand that I probably have a duplicate variable somewhere. I have not found a duplicate variable in here. I've tried adding the console logging above and I haven't learned anything new from it. The only solution I haven't tried yet is the one suggesting downloading the source code of the .Net Framework and modifying it to trace further into the exception.

So, what else can I do? This is driving me batty.


Solution

  • The answer, arrived at by a co-worker, was simple, and I feel like an idiot for not thinking of it. There was indeed a case of two variables within the class that differed only in case, one which I had generated and one which the system had generated, both in different source files by using the partial class functionality. The problem was eventually solved by combing through the Object Browser in the area of objects that were being used in that section. A more elegant way of searching for the problem might have involved using Reflection to check for classes that had variables that differed only in case.