简体   繁体   English

Visual Studio 2015 添加类,错误:“对象已存在”

[英]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 名为 '' 的文件或文件夹已存在 Visual Studio 2012
  • ATL simple object wizard - "Object Xxx already exists" error ATL 简单对象向导 - “对象 Xxx 已存在”错误

  • The error: 错误:
    I try to add a simple class 我尝试添加一个简单的类 在此处输入图片说明 and then proceed to the wizard where I get the following Error] 2 : 然后继续向导,在那里我收到以下错误] 2 在此处输入图片说明 "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 我无法将“MainGame”类(和其他一些名称)添加到任何项目中,即使我创建了一个新项目

    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.当我删除了一个不小心从另一个解决方案中的项目复制过来的 Release 文件夹时发生了错误。 All now non-functional class names are derived from the object files within that Release folder.现在所有的非功能类名称都派生自该 Release 文件夹中的目标文件。

    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.我对所有建议持开放态度,虽然这个“错误”并没有使编程变得不可能,但不能使用常用的类名是很烦人的。

    Yeah, also saw that.是的,也看到了。

    I think I have created a C++ class, decided I don't like it, reverted changes using github app.我想我已经创建了一个 C++ 类,决定我不喜欢它,使用 github 应用程序恢复了更改。 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.该名称污染了 sqlite 数据库。 And because I had that VC.db in my .gitignore, git hasn't reverted that.因为我的 .gitignore 中有那个 VC.db,git 没有恢复它。

    To fix, quit visual studio, delete the file $(SolutionName).VC.db in your $(SolutionDir) folder, restart visual studio, clean and rebuild your project[s].要修复,请退出 Visual Studio,删除 $(SolutionDir) 文件夹中的文件 $(SolutionName).VC.db,重新启动 Visual Studio,清理并重建您的项目 [s]。

    Update: Modern versions of Visual Studio usually keep these SQLite databases inside .vs folder under $(SolutionDir).更新: Visual Studio 的现代版本通常将这些 SQLite 数据库.vs在 $(SolutionDir) 下的.vs文件夹中。

    Seems like VS caching issue.似乎是 VS 缓存问题。 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.我所做的是添加一个具有不同名称的类,比如MainGame1 ,然后它允许我添加。 Then I just renamed the Class name, CPP and header file name to my like.然后我只是将类名、CPP 和头文件名重命名为我喜欢的。

    Manually create example.h and example.cpp in Solution directory then:在解决方案目录中手动创建 example.h 和 example.cpp 然后:

    Add -> Existing Item... -> add created file to your project. Add -> Existing Item... -> 将创建的文件添加到您的项目中。

    This trick work for me after clean $(SolutionName).VC.db file.这个技巧在清理 $(SolutionName).VC.db 文件后对我有用。

    即使您的项目中没有任何 .h .cpp,请确保您在任何其他 .h .cpp 文件中也没有“MainGame”声明或定义作为内部类。

    I just ran into the same problem.我刚刚遇到了同样的问题。 To solve it using your example names:要使用您的示例名称解决它:

    1. Manually create an empty "MainGame.h" and "MainGame.cpp."手动创建一个空的“MainGame.h”和“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.我怀疑我会再次遇到没有从数据库中清除的其他名称。

    Got the same issue, which was solved by cleaning up the visual studio cache.遇到了同样的问题,通过清理 Visual Studio 缓存解决了。

    Just close VS, clean up the files in (for VS2015) %USERPROFILE%\\AppData\\Local\\Microsoft\\VisualStudio\\14.0\\ComponentModelCache %USERPROFILE%\\AppData\\Local\\Temp只需关闭 VS,清理(对于 VS2015)%USERPROFILE%\\AppData\\Local\\Microsoft\\VisualStudio\\14.0\\ComponentModelCache %USERPROFILE%\\AppData\\Local\\Temp 中的文件

    , and restart VS. ,然后重新启动 VS。 It should go back to normal.它应该会恢复正常。

    再次启动 VS 时删除现有的 *.sln 它将允许没有任何错误。

    声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

     
    粤ICP备18138465号  © 2020-2024 STACKOOM.COM