Search code examples
c++visual-studiovisual-studio-2012c++-clivisual-studio-designer

Visual Studio Designer won't work for a C++/CLI file in VS2012 while it did in VS2005. Know why?


I know, I know, this issue has been addressed many times. "Just forward declare your class before any other forward declarations and it will work."

I re-open this question because for me it doesn't work at all. I have Visual Studio 2012 update 1. I develop in C++/CLI in x64 on Win 7/x64. Here is how my header file looks like:

#pragma once

namespace MyNameSpace
{
    ref class MyForwardDeclaredClass;

    public ref class MyClass : public System::Windows::Forms::UserControl
    {
    public:
        // My declaration here

        MyForwardDeclaredClass^ mObjectPtr;
    }
}

When I launch the design, I get the message The class MyClass can be designed, but is not the first class in the file. Visual Studio requires that designers use the first class in the file.

So, following the recommendations of many persons (and these recommendations seem to work for many), I added the line:

ref class MyClass; // <-- ADDED FORWARD DECLARATION HERE!
ref class MyForwardDeclaredClass;

public ref class MyClass : public System::Windows::Forms::UserControl
{
    // ...

and I still get the same error message. Notice that I also restarted Visual Studio, I cleaned the project, and I rebuilt it.

Note: I tried to remove the forward declaration and to add a #include "MyForwardDeclaredClass.h" instead. I got the same error.

We migrated from VS2005 to VS2012 recently. With VS2005, the designer use was so-so. But it worked most of the time. Now, most of the time I cannot make it work and I don't find any workaround.

Any idea?

EDIT

OK, following the advices I was given, I erased the .suo and the .sdf files then reloaded the solution then rebuilt it. Nothing good. I recreate a new project using the same code files: nothing good. And yes, I have .cpp files in my project ;-)


Solution

  • The solution was quite easy: I had to reset default options in Tools-Options-Text Editor-C/C++/Advanced, section Browsing/Navigation.

    If someday you experience the same problem, just try to restore the default values for these options.