locked
"An item with the same key has already been added" error with MVC Controller and View Generator RRS feed

  • Question

  • User-1232708435 posted

    Hi There;

    I have modelled my application and all my classes are extended from a single base class. So my objects have their own tables on DB (configured with DBContext, totable function) but they have a common ancestor table which creates the primary keys for all its sub classes.

    With this class configuration, when I try to create a Controller and its views using the Add Controller wizard in Visual Studio for any of the sub classes, I get an error saying that "There was an error running the selected code generator: 'An item with the same key has already been added.'"

    How can I get past that?

    Thanks.


    PS: So far, I tried and failed to find any duplicate resource files in my project file as suggested resolution to several errors with same error text and previous Visual Studio versions. My problem is with Visual Studio 2015 w/ Update 2, language is C#.

    Monday, May 16, 2016 9:29 AM

Answers

  • User-1636183269 posted

    It looks your model which contains the same property twice. Perhaps share your code, so we can help better or see you can use new to instantiate.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, May 16, 2016 10:38 AM
  • User-166373564 posted

    Hi Ysayita,


    PS: So far, I tried and failed to find any duplicate resource files in my project file as suggested resolution to several errors with same error text and previous Visual Studio versions. My problem is with Visual Studio 2015 w/ Update 2, language is C#.

    Besides what Das.Sandeep mentioned above, you could also consider deleting that Controller and its view, and create them again, check whether it can fix it.

    Regards,

    Angie

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, May 23, 2016 6:18 AM

All replies

  • User-1636183269 posted

    It looks your model which contains the same property twice. Perhaps share your code, so we can help better or see you can use new to instantiate.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, May 16, 2016 10:38 AM
  • User-166373564 posted

    Hi Ysayita,


    PS: So far, I tried and failed to find any duplicate resource files in my project file as suggested resolution to several errors with same error text and previous Visual Studio versions. My problem is with Visual Studio 2015 w/ Update 2, language is C#.

    Besides what Das.Sandeep mentioned above, you could also consider deleting that Controller and its view, and create them again, check whether it can fix it.

    Regards,

    Angie

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, May 23, 2016 6:18 AM