Resharper’s bug that removes regions

Tuesday, 18 December 2007 05:34 by Alan Mojab

One of Smarties 2008 users have recently reported that when he uses Resharper’s “Code Reformat” command with “Reorder member types” checked all regions that were created by Smarties 2008 are removed.

I ran several tests first before concluded there was an annoying bug in Resharper 3.x. Smarties 2008 uses a type called EditPoint2 to insert #region directives to the documents. This type is nicer to work with but slower to use than other available types such as TextSelection since it uses buffering technique.

Somehow Resharper cannot see #regions being inserted by EditPoint2 type but it has no problem with members. There is something even more evil about this bug. If you insert regions to code files out side of Microsoft Visual Studio environment and then run the “Code Reformat” command against those files all #regions will be removed too. Discovering this ensured me this bug has nothing to do with the technique I used for inserting #regions to the document and this is just an annoying bug in Resharper.

I have contacted the support team of JetBrains and their reply was;

"By default, ReSharper should not remove existing regions inside classes. Please open ReSharper > Options > Languages > C# > Type MemberLayout and make sure 'Use default patterns' option is enabled. Please also try upgrading to the latest ReSharper 3.1 RC which is available here: http://www.jetbrains.net/confluence/display/ReSharper/Download. Thank you!

Andrey Serebryansky
Support Engineer
JetBrains, Inc"

In all my tests 'Use default patterns' was already enabled. I don’t use Resharper so I would suggest to wait until they fix the problem or alternatively you can pester them for a quick fix update.