codecadwallader / codemaid

CodeMaid is an open source Visual Studio extension to cleanup and simplify our C#, C++, F#, VB, PHP, PowerShell, JSON, XAML, XML, ASP, HTML, CSS, LESS, SCSS, JavaScript and TypeScript coding.
http://www.codemaid.net
GNU Lesser General Public License v3.0
1.88k stars 352 forks source link

Start Position must lie inside rance #1031

Open TechnVision opened 6 months ago

TechnVision commented 6 months ago

Environment

Here is the stack trance that I get in output window, but not so sure why this happens, my project builds and works fine but some sort of error is thrown here.

[CodeMaid Handled Exception 12:00:04 AM] CodeMaid Cleanup for 'FrmCreateNewCompany.cs' was stopped: System.ArgumentException: startingPosition (132497) must lie inside searchRange ([0..132496)) Parameter name: startingPosition at Microsoft.VisualStudio.Text.Find.Implementation.BaseFinderForSnapshot.AdjustSearchRange(Int32 startingPosition, Span searchRange) at Microsoft.VisualStudio.Text.Find.Implementation.BaseFinderForSnapshot.TryFind(Int32 startingPosition, Span searchRange, Span& result) at Microsoft.VisualStudio.Text.Find.Implementation.BaseFinderForSnapshot.TryFind(Int32 startingPosition, Span& result) at SteveCadwallader.CodeMaid.Helpers.TextDocumentHelper.<>cDisplayClass4_0.b0() in C:\projects\codemaid\CodeMaidShared\Helpers\TextDocumentHelper.cs:line 130 at SteveCadwallader.CodeMaid.Helpers.TextDocumentHelper.<>cDisplayClass20_0.<b0>d.MoveNext() in C:\projects\codemaid\CodeMaidShared\Helpers\TextDocumentHelper.cs:line 448 --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.VisualStudio.Threading.JoinableTask.CompleteOnCurrentThread() at SteveCadwallader.CodeMaid.Helpers.TextDocumentHelper.RunOnUIThread(Action action) in C:\projects\codemaid\CodeMaidShared\Helpers\TextDocumentHelper.cs:line 450 at SteveCadwallader.CodeMaid.Helpers.TextDocumentHelper.TryFindNextMatch(EditPoint startPoint, EditPoint& endPoint, String patternString) in C:\projects\codemaid\CodeMaidShared\Helpers\TextDocumentHelper.cs:line 144 at SteveCadwallader.CodeMaid.Logic.Cleaning.UpdateLogic.UpdateEndRegionDirectives(TextDocument textDocument) in C:\projects\codemaid\CodeMaidShared\Logic\Cleaning\UpdateLogic.cs:line 72 at SteveCadwallader.CodeMaid.Logic.Cleaning.CodeCleanupManager.RunCodeCleanupCSharp(Document document) in C:\projects\codemaid\CodeMaidShared\Logic\Cleaning\CodeCleanupManager.cs:line 335 at SteveCadwallader.CodeMaid.Logic.Cleaning.CodeCleanupManager.<>c__DisplayClass19_0.b__0() in C:\projects\codemaid\CodeMaidShared\Logic\Cleaning\CodeCleanupManager.cs:line 170 at SteveCadwallader.CodeMaid.Helpers.UndoTransactionHelper.Run(Action tryAction, Action`1 catchAction) in C:\projects\codemaid\CodeMaidShared\Helpers\UndoTransactionHelper.cs:line 55

asdfchlwnsgy1236 commented 3 months ago

I have exactly the same issue. From my testing, it happens for certain when the entire file is surrounded with #if/#endif. Not sure about other preprocessor macros, though.