Exception when cleaning up all code: InsertFileHeaderDocumentStart must be called on the UI thread
Environment
- Visual Studio version: 2022 Professional 17.0.0
- CodeMaid version: 12.0
- Code language: C#
Description
I run "Clean all code" and I get this exception for almost every file:
[CodeMaid Warning 08:10:56 ] Activation was not completed before cleaning began for 'Archive.cs'
[CodeMaid Handled Exception 08:10:59 ] CodeMaid Cleanup for 'Archive.cs' was stopped: System.Runtime.InteropServices.COMException (0x8001010E): InsertFileHeaderDocumentStart must be called on the UI thread.
at Microsoft.VisualStudio.Shell.ThreadHelper.ThrowIfNotOnUIThread(String callerMemberName)
at SteveCadwallader.CodeMaid.Logic.Cleaning.FileHeaderLogic.InsertFileHeaderDocumentStart(TextDocument textDocument, String settingsFileHeader) in C:\projects\codemaid\CodeMaidShared\Logic\Cleaning\FileHeaderLogic.cs:line 166
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.<Cleanup>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
Thanks for reporting the issue. I haven't been able to reproduce it but I suspect that it may need the same UIThread.Run logic that was added here: https://github.com/codecadwallader/codemaid/blob/dev/CodeMaidShared/Helpers/TextDocumentHelper.cs#L72 to be added in places like here: https://github.com/codecadwallader/codemaid/blob/dev/CodeMaidShared/Logic/Cleaning/FileHeaderLogic.cs#L164
Thanks. Let me know if I can do anything to help reproducing the issue.
It looks like it it only happens if I have configured the setting "File header insert":
If I remove it, I do not get the exceptions.