Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why has Visual Studio marked my class as a component?

A class diagram

I have copy pasted some classes into this project, some from other projects. At some point VS has marked Class1 as a component (you can see from the icon shown in the screenshot above). Class2 is OK. There's no difference in the File Properties and no interesting difference in the code between Class1 and Class2 (*except see edit below)

It doesn't stop the code from compiling or running. Is it in fact a problem at all? It is inconvenient in that the IDE tries to open the Design window if you double click the file.

How does this happen, and how to fix?

Edit: Actually, there are interesting differences in the code window. At least, there must be, since removing a large chunk of the code causes the Solution Explorer to revert the file to a Class file. Restore the chunk and the file goes back to being a Component. Currently... investigating.

like image 589
hawbsl Avatar asked Jan 18 '11 09:01

hawbsl


2 Answers

I'm not sure why it does this thing, but I know how to get rid of it. Before your class put:

[System.ComponentModel.DesignerCategory("Code")]

It should work.

like image 148
Mat Avatar answered Nov 15 '22 19:11

Mat


For the "why" part of your question (taken from this post which appears to be a duplicate):

Class with System.ComponentModel.Component on their inheritance path are automatically treated as "components" within Visual Studio (2008), triggering a different icon for the source file:

like image 43
dbruning Avatar answered Nov 15 '22 19:11

dbruning