Anyone know a good way to find out where i have an extra #region or #endregion in my code? I have about 5000 lines of c# code and i'm trying to do it manually right now. Any help is appreciated.
Asked
Active
Viewed 2,742 times
4
-
@toosweetnightmare Tejs is correct; the fact that you have a mismatched region is a sign of a larger problem. After you find your issue, I recommend doing what you can to keep each class as small as possible. – George Stocker Jun 02 '11 at 20:31
-
2Partial classes are great for this, or separate classes ;-) – CodeNaked Jun 02 '11 at 20:33
-
1I have it broken into classes and i like to break the code in the classes up into little regions with titles to manage it. It might not be best practice but i'm not a software engineer and it works for me. – toosweetnitemare Jun 02 '11 at 20:35
-
1It sounds kind of like it's not working actually. I think the idea is that your class is too big. – recursive Jun 02 '11 at 20:39
-
I think ill just take Tejs advice and remove all of my #region and #endregion – toosweetnitemare Jun 02 '11 at 20:44
4 Answers
8
Do CTRL+M CTRL+L - to close up all the regions. Then expand them one at a time on the left (little +
sign) until you see #region XXX
that doesnt have matching #endregion
Should look like this:

Glorfindel
- 21,988
- 13
- 81
- 109

SwDevMan81
- 48,814
- 22
- 151
- 184
-
Thanks SwDevMan81. i did this already. I might just do a replace on all my #regions with a // and replace my #endregion with // too just to remove the issue. – toosweetnitemare Jun 02 '11 at 20:36
-
thanks for the update. Im going to try that now. Ill be back in a few minutes and let you know how it went. – toosweetnitemare Jun 02 '11 at 20:49
-
That worked. Ended up being a stupid typo actually. Thank you very much! – toosweetnitemare Jun 02 '11 at 20:51
1
Just had this issue myself,
easiest way for me to find out where I had deleted an endregion was to do a compare with the last file in source control.
the line was then highlighted and easy to find.

WraithNath
- 17,658
- 10
- 55
- 82
-
an excellent suggestion. I unfortunately did not have a previous copy to use for source control but i can see how this would have been a very useful. Thank you for adding to my question! – toosweetnitemare Sep 27 '12 at 15:16
1
Click Ctrl+M, M
it will collapse all properly matching regions. The one that doesn't match will not be collapsed so you can fix it.

Teoman Soygul
- 25,584
- 6
- 69
- 80
-
Doing this closed everything except for a lone #endregion i had to put at the end to remove the error – toosweetnitemare Jun 02 '11 at 20:39
1
What happens when you use the shortcuts to collapse all?
CTRL+M CTRL+O - Collapse all regions not recursively
It should collapse all but the region that has the mismatch.

George Stocker
- 57,289
- 29
- 176
- 237