Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The operation 'Create Declaration / Definition' could not be completed: code element is read only

I am developing a C++ project with CMake build system in Visual Studio 2015 on Win10 64bit.

I used to create function definitions in C++ file by clicking on the declaration in the header and then Quick Actions and Refactorings->Create Declaration / Definition.

For some reason this feature does not work in my project anymore. Whenever I try to use "Create Definition" I get this error message:

The operation 'Create Declaration / Definition' could not be completed for the following reason:

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

error

Also, when I choose Quick Actions and Refactorings small popup window appears with just two options:

two options window

When this feature works VS usually shows window with four options, like this:

four options window

I know there are tons of similar questions on SO, but none of the seem to address this particular error. I've tried everything suggested so far:

  • Reboot VS and Windows
  • Clean solution
  • Delete the build folder entirely (with all the .suo and .user files and hidden directories) and re-create it with CMake
  • Delete the content of %LocalAppData%\Microsoft\VisualStudio\14.0\ComponentModelCache
  • Look in the .err. file in directory %LocalAppData%\Microsoft\VisualStudio\14.0\ComponentModelCache - no relevant errors.
  • Reset all VS user data using devenv.exe /resetuserdata
  • Close all other editors, explorer windows etc.

None of this has any effect.

This feature is great and the issue is very annoying. If anyone has any clue, please help.

like image 574
Aleksei Petrenko Avatar asked Oct 25 '25 04:10

Aleksei Petrenko


1 Answers

Ok, my bad. I had a mistake in CMake scripts, that's why some of the header files were not included in the Visual Studio project. If you have this error make sure both .cpp and .hpp files are added to your VS project files.

like image 188
Aleksei Petrenko Avatar answered Oct 26 '25 18:10

Aleksei Petrenko