Error message in MFC/RC on VS2008 - "Add/Remove operation is impossible, because the code element 'Cxxxx' is read only"
Asked Answered
B

7

7

I have searched online and get inconsistent answers that don't fix the problem for me. I created a dialog box and then clicked ont he wizard to create a class for me. Unfortunately it named the class and file badly badly so I renamed the file. Now visual studio won't let me do anything through the gui to the dlg resource - like hook up a button even handler, etc. I get the message box:

"Add/Remove operation is impossible, because the code element 'Cxxxx' is read only"

This is a real problem because adding handlers and things manually through the code is tedious and one of the developers just isn't able to do it that way - he needs the GUI to manipulate the events.

I have tried deleting the ncb file and rebuilding the project, but no luck at all. MS apparently has not fixed this problem after 4 years or so (based on the searches I have seen online.

I can't add variables, event handlers or anything else useful through the MFC app wizard gui. I can only do so by editing the cpp and h files.

Does anyone have any suggestions?

Betake answered 15/2, 2011 at 3:2 Comment(6)
Not sure how we can solve this without being able to repro it. I'm sure the VS developers feel the same way about the many similar bugs you've seen posted online. The one bug report I see posted that included a repro project has been marked as fixed in VS 2010. Maybe it's time to upgrade. Although I've never encountered this bug in either version, and I frequently change my mind about a class's name after using the wizards.Josefina
@Cody - upgrading would be nice - unfortunately we are using some libraries that are unsupported still for 2010...Betake
What kind of libraries are unsupported in VS 2010? I haven't seen such a thing; were they really exploiting bugs in the VS 2008 compiler? And even if so, you can set VS 2010 to use the VS 2008 compiler as long as you have both versions installed.Josefina
@Cody - financial data feed libraries. If we ever have a support call with them for a particular version they will just deny support. They have not tested their libraries with it (yet) so they won't support it.Betake
along with the .ncb, did you try deleting the <username>.user file also?Salimeter
I ran into this problem with Visual Studio 2005 as well after making a modification to the resource file using a text editor to copy a dialog template from one resource file to another. deleting the .suo file worked for me.Claudication
M
6

I added existing files in a VS2008 project and had the problem too. I fixed it by deleting the .suo file and recompiling the solution.

Maybe it helps somebody who comes across this problem.

Markova answered 27/1, 2014 at 12:29 Comment(2)
This worked for me as well. Thanks! This was driving me nuts! What I had done was to directly edit the .rc resource file and put a new dialog in by copying the dialog template from another resource file. After I did that I seemed to run into this problem. I tried deleting the copied resource template and it did not make a difference. So I exited Visual Studio 2005, deleted the .suo file for the solution, and then restarted Visual Studio 2005 and am now able to use the wizard to add event handlers.Claudication
Note: in my case it helped me to delete the .ncb as well, as mentioned in the OP's question.Aggi
V
2

I have managed (accidentally) to reproduce the same problem. I have defined DECLARE_EVENTSINK_MAP() and full

BEGIN_EVENTSINK_MAP(CDlgMessage, CDialog)
ON_EVENT(CDlgMessage, IDC_GM_VIEW1, 1, CDlgMessage::GMEventGmView1, VTS_I2 VTS_BSTR VTS_BSTR)
END_EVENTSINK_MAP()

and than I have deleted manually whole BEGIN-END section, but I have left DECLARE undeleted. When I later on tried to make add event handler by GUI I have received mentioned response. Simple deletion of the DECLARED part have solved the problem.

I believe that this can be copied to all similar problems.

Srdjan

Verrucose answered 25/10, 2012 at 13:41 Comment(0)
C
1

I know this might be coming a bit late, but have you renamed the class itself too? If so, you may have forgotten to rename the

DECLARE_DYNAMIC(RandomClass, CDialog/alternative)  

and

IMPLEMENT_DYNAMIC(RandomClass)

The documentation for these calls is not very thorough, but when I tried to create a class to which I could add an event I got a similar error when trying to add an event to that class:

http://msdn.microsoft.com/en-us/library/ywz9k63y%28v=vs.90%29.aspx

Consanguineous answered 25/1, 2012 at 16:30 Comment(0)
B
1

How I fixed this (deleting .ncb/.suo/.user files and rebuilds did not help)...

I noticed the following peculiarity when this error was happening in my VS 2008 project:

  1. It happened in one dialog+class, not in the others.
  2. In the .cpp class file for the broken dialog, the scope selector had only "(Global Scope)" item, no other lines (expected class was not present)
  3. I also checked the .h class file, and scope selector there was ok.

I fixed this problem in #2 first (explained below), then exited VS, deleted *.ncb, *.suo files, restarted VS, rebuilt the project and the wizards started working again.

To fix the scope selector problem in #2 I first narrowed it down to the headers not included into the class's .h file, i.e. I had some types used inside the class declaration, but no header in the .h file that declared these types. So if I were to include the class's .h file into a clean .cpp file, it won't compile. The rest of the project was compiling OK, because all needed files were added to all corresponding .cpp files before the class's .h. After I added all necessary headers to the top of class's .h (so clean .cpp file would compile), the scope selector in .cpp file filled up correctly and in turn it fixed the wizard.

On a sidenote: there is a school of thought to not include any other .h files into any of .h files, and Microsoft seems to stick to this way quite frequently (luckily not always). I typically follow different inclusion policy - to always include headers with all used declarations into .h file, so when I need to use a module, I have to include only its .h file. In the rare occasion that I had when this did not happen, VS wizard chocked (or IntelliSense chocked that wizard relies on). It makes my comittment to this inclusion policy stronger. The only exclusion to this policy is not putting any stdafx.h, windows and MFC files into module's .h file - it is done differently for the reason of precompiled headers.

Bibliology answered 13/12, 2014 at 1:17 Comment(0)
M
1

Just an FYI that I encountered the same issue in Visual Studio 2010 SP1.

Deleting the SDF file (the Visual Studio 2010 equivalent of the NCB of prior versions) fixed the problem.

(I had tried many other things first, including cleaning the project and rebuilding, deleting the .suo file, etc., to no avail. However whether those actions were needed in ADDITION to finally deleting the SDF file, I do not know.)

Muniments answered 18/8, 2016 at 20:12 Comment(0)
W
0

Deleting the solution .ncb file and rebuild worked for me too in Visual studio 2008. I should mention I started facing this problem after migrating my code to a new PC.

Wellmeaning answered 25/9, 2016 at 1:39 Comment(0)
A
0

I had the same problem with VS2005. I tried deleting *.ncb and *.suo but to no avail.

In the end, I just need to close the file that is being complaint (because it's being opened, VS can't automatically add new code to the file when we perform some actions on the GUI resources such as adding an Event Handler to a Menu Item).

Ashtonashtonunderlyne answered 19/1, 2017 at 13:45 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.