Bjartskular
Bjartskular

Reputation: 85

Visual Studio 2015 Add Class, Error: "object already exists"

Other similar but to my knowledge non-related questions:

  • A file or folder with the name '' already exists Visual Studio 2012
  • ATL simple object wizard - "Object Xxx already exists" error

  • The error:
    I try to add a simple class enter image description here and then proceed to the wizard where I get the following Error]2: enter image description here "Object already exists".
    I can't add the class "MainGame" (and a few other names) to any project, not even if I create a new project

    How to recreate said bug/error:
    The error occured when I deleted a Release folder I'd accidentally copied over from a project in another solution. All now non-functional class names are derived from the object files within that Release folder.

    Solution:
    I have no solution.

    My questions are:
    Have anyone else had this or a similar issue?
    If so, have you solved it and what is your solution?

    I am open to all suggestions and while this 'bug' isn't making programming impossible it is quite annoying not being able to use frequently used class names.

    Upvotes: 7

    Views: 5949

    Answers (7)

    Soonts
    Soonts

    Reputation: 21936

    Yeah, also saw that.

    I think I have created a C++ class, decided I don’t like it, reverted changes using github app. But the name was good, so I tried creating same class again. Saw the exact same error as you’re having.

    The name polluted the sqlite database. And because I had that VC.db in my .gitignore, git hasn't reverted that.

    To fix, quit visual studio, delete the file $(SolutionName).VC.db in your $(SolutionDir) folder, restart visual studio, clean and rebuild your project[s].

    Update: Modern versions of Visual Studio usually keep these SQLite databases inside .vs folder under $(SolutionDir).

    Upvotes: 11

    Vaman Acharya
    Vaman Acharya

    Reputation: 325

    Delete the existing *.sln when you launch VS again it will allow without any error.

    Upvotes: 0

    user12961058
    user12961058

    Reputation: 1

    Got the same issue, which was solved by cleaning up the visual studio cache.

    Just close VS, clean up the files in (for VS2015) %USERPROFILE%\AppData\Local\Microsoft\VisualStudio\14.0\ComponentModelCache %USERPROFILE%\AppData\Local\Temp

    , and restart VS. It should go back to normal.

    Upvotes: 0

    trilioth
    trilioth

    Reputation: 1

    I just ran into the same problem. To solve it using your example names:

    1. Manually create an empty "MainGame.h" and "MainGame.cpp." (...probably doesn't have to be empty.)
    2. Add both files to your project.
    3. Then finally remove both files from your project, deleting the files from disk.

    After that, it will let you use that name when creating a new class with the class wizard. It's neither an elegant solution nor a complete one. It will let you get past that one problem. I suspect I'll run into it again with other names that aren't getting cleaned out of the database.

    Upvotes: 0

    mohammad madani
    mohammad madani

    Reputation: 880

    Manually create example.h and example.cpp in Solution directory then:

    Add -> Existing Item... -> add created file to your project.

    This trick work for me after clean $(SolutionName).VC.db file.

    Upvotes: 1

    Bit_Pulse
    Bit_Pulse

    Reputation: 356

    Seems like VS caching issue. I too faced this issue and your solution did not work for me either.

    What I did is add a Class with different name lets say MainGame1 and then it allowed me to add. Then I just renamed the Class name, CPP and header file name to my like.

    Upvotes: 1

    Shih Kuang Chu
    Shih Kuang Chu

    Reputation: 1

    Even though you don't have any .h .cpp in your project, make sure you don't have "MainGame" declaration or definition in any other .h .cpp file as an inner class either.

    Upvotes: 0

    Related Questions