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.89k stars 356 forks source link

VS 2022 - Clean Up Selected Code gives error #898

Open apsthisdev opened 2 years ago

apsthisdev commented 2 years ago

Hi,

The CodeMaid for VS 2022 command Cleanup Selected Code on .csproj or on a namespace folder throws an exception.

image

I have to manually open each .cs file and then run Cleanup Selected Code individually. This is a pain for project with lot of files.

Earlier version was opening the file and then cleaning it up.

Here is the log that I get...

[CodeMaid Warning 02:27:55 PM] Activation was not completed before cleaning began for 'test.cs' [CodeMaid Handled Exception 02:28:01 PM] CodeMaid Cleanup for 'test.cs' was stopped: System.Runtime.InteropServices.COMException (0x8001010E): ReplaceFileHeaderDocumentStart must be called on the UI thread. at Microsoft.VisualStudio.Shell.ThreadHelper.ThrowIfNotOnUIThread(String callerMemberName) at SteveCadwallader.CodeMaid.Logic.Cleaning.FileHeaderLogic.ReplaceFileHeaderDocumentStart(TextDocument textDocument, String settingsFileHeader) in C:\projects\codemaid\CodeMaidShared\Logic\Cleaning\FileHeaderLogic.cs:line 237 at SteveCadwallader.CodeMaid.Logic.Cleaning.CodeCleanupManager.RunCodeCleanupCSharp(Document document) in C:\projects\codemaid\CodeMaidShared\Logic\Cleaning\CodeCleanupManager.cs:line 264 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

codecadwallader commented 2 years ago

Thanks for reporting the issue. Based on the call stack it looks like it is specifically the usage of a file header that is causing an issue. Out of curiosity if you remove the file header does it work as expected?