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.92k stars 362 forks source link

VS2022: Attempted to edit TextBuffer on the wrong thread #849

Closed kfrancis closed 3 years ago

kfrancis commented 3 years ago

Environment

Description

Solution clean and getting these errors:

[CodeMaid Handled Exception 12:49:56 PM] CodeMaid Cleanup for 'ClaimAssertionBackchannelHandler.cs' was stopped: System.InvalidOperationException: Attempted to edit TextBuffer on the wrong thread.
   at Microsoft.VisualStudio.Text.Implementation.BaseBuffer.TextBufferBaseEdit..ctor(BaseBuffer baseBuffer)
   at Microsoft.VisualStudio.Text.Implementation.TextBuffer.CreateEdit(EditOptions options, Nullable`1 reiteratedVersionNumber, Object editTag)
   at Microsoft.VisualStudio.Text.Implementation.BaseBuffer.CreateEdit()
   at SteveCadwallader.CodeMaid.Helpers.TextDocumentHelper.ReplaceAll(ITextBuffer textBuffer, IEnumerable`1 replacements) in C:\src\codemaid\CodeMaidShared\Helpers\TextDocumentHelper.cs:line 385
   at SteveCadwallader.CodeMaid.Helpers.TextDocumentHelper.SubstituteAllStringMatches(TextDocument textDocument, String patternString, String replacementString) in C:\src\codemaid\CodeMaidShared\Helpers\TextDocumentHelper.cs:line 292
   at SteveCadwallader.CodeMaid.Logic.Cleaning.CodeCleanupManager.RunCodeCleanupCSharp(Document document) in C:\src\codemaid\CodeMaidShared\Logic\Cleaning\CodeCleanupManager.cs:line 272
   at SteveCadwallader.CodeMaid.Logic.Cleaning.CodeCleanupManager.<>c__DisplayClass19_0.<Cleanup>b__0() in C:\src\codemaid\CodeMaidShared\Logic\Cleaning\CodeCleanupManager.cs:line 170
   at SteveCadwallader.CodeMaid.Helpers.UndoTransactionHelper.Run(Action tryAction, Action`1 catchAction) in C:\src\codemaid\CodeMaidShared\Helpers\UndoTransactionHelper.cs:line 55
kfrancis commented 3 years ago

Doesn't seem to correspond to what the content is, happens randomly during a large solution clean.

codecadwallader commented 3 years ago

Thanks for reporting @kfrancis ! There's an updated build on the main issue if you want to give it a shot and let us know if that helped?

kfrancis commented 3 years ago

Perfect!

I do see Activation was not completed before cleaning began for warnings, but I don't see the same issue with TextBuffer now.