Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exception when cleaning up all code: InsertFileHeaderDocumentStart must be called on the UI thread #859

Open
FStapenhorst opened this issue Nov 9, 2021 · 3 comments · May be fixed by #912

Comments

@FStapenhorst
Copy link

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
@codecadwallader
Copy link
Owner

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

@FStapenhorst
Copy link
Author

Thanks. Let me know if I can do anything to help reproducing the issue.

@FStapenhorst
Copy link
Author

It looks like it it only happens if I have configured the setting "File header insert":
Screenshot 2021-11-17 at 18 54 31
If I remove it, I do not get the exceptions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants