codemaid icon indicating copy to clipboard operation
codemaid copied to clipboard

Clean up does NOT work in Visual Studio 2022

Open Duelbat opened this issue 3 years ago • 20 comments

UPDATE: After updating to the latest Visual Studio 2022 (17.1.0) and reinstalling Codemaid, everything is working!!!

Duelbat avatar Feb 11 '22 21:02 Duelbat

💯

This was working for a while, but recently it has stopped working. We are using a solution configuration file for our settings.

brogdogg avatar Feb 15 '22 17:02 brogdogg

If I can find time this week, I may try to debug this myself. I'm new to CodeMaid, but like the concept thus far.

brogdogg avatar Feb 16 '22 04:02 brogdogg

Thanks for reporting the issue. I have not been able to reproduce it. Can you please enable diagnostics mode (CodeMaid->Options->Diagnostics mode) and see if any useful information is provided in the Output tool window?

Some other information that would be helpful to provide:

  • Visual Studio version. I am using VS2022 17.1.0 Preview 6.0
  • The project type that is affected (e.g. C# class library, ASP.NET application, etc.)

codecadwallader avatar Feb 17 '22 12:02 codecadwallader

@codecadwallader

I am encountering this issue on an Azure Functions project. Here is the CodeMaid output:

[CodeMaid Handled Exception 10:56:53 AM] CodeMaid Cleanup for 'Function1.cs' was stopped: System.Runtime.InteropServices.COMException (0x80004005): Error HRESULT E_FAIL has been returned from a call to a COM component.
   at System.Runtime.InteropServices.Marshal.ThrowExceptionForHRInternal(Int32 errorCode, IntPtr errorInfo)
   at Microsoft.VisualStudio.LanguageServices.Implementation.Utilities.Exceptions.ThrowEFail()
   at Microsoft.VisualStudio.LanguageServices.Implementation.CodeModel.InternalElements.AbstractCodeElement.LookupNode()
   at Microsoft.VisualStudio.LanguageServices.Implementation.CodeModel.InternalElements.AbstractCodeElement.GetStartPoint(vsCMPart part)
   at EnvDTE.CodeElement.GetStartPoint(vsCMPart Part)
   at SteveCadwallader.CodeMaid.Model.CodeItems.BaseCodeItemElement.get_StartPoint() in C:\src\codemaid\CodeMaidShared\Model\CodeItems\BaseCodeItemElement.cs:line 43
   at SteveCadwallader.CodeMaid.Logic.Cleaning.InsertBlankLinePaddingLogic.InsertPaddingBeforeCodeElements[T](IEnumerable`1 codeElements) in C:\src\codemaid\CodeMaidShared\Logic\Cleaning\InsertBlankLinePaddingLogic.cs:line 254
   at SteveCadwallader.CodeMaid.Logic.Cleaning.CodeCleanupManager.RunCodeCleanupCSharp(Document document) in C:\src\codemaid\CodeMaidShared\Logic\Cleaning\CodeCleanupManager.cs:line 283
   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

jasonnissen avatar Feb 17 '22 16:02 jasonnissen

@codecadwallader Thank you so much for getting back to me. I luuuuuuuuv this magic utility and worked with it in VS 2019. I am happy to report that after uninstalling VS 2022 PREVIEW and running the latest Visual Studio 2022 update to Version 17.1.0 then reinstalling CODEMAID, EVERYTHING is working !!!!!!!
P.S. If you ever change to a pricing model, I amongst many others would be happy to pay!! Many thanks, appreciate your time and efforts!

Duelbat avatar Feb 17 '22 21:02 Duelbat

I have to report that this is once again not working. There was some strange behavior of it not allowing me to save a Razor page in my Blazor project. I then uninstalled it and reinstalled it. After new installation, it does not work again.

Duelbat avatar Feb 22 '22 03:02 Duelbat

Can you please enable diagnostics mode (CodeMaid->Options->Diagnostics mode) and see if any useful information is provided in the Output tool window?

codecadwallader avatar Mar 11 '22 13:03 codecadwallader

met the same problem, no action is functioning. Diagnostics mode enabled, no output seen. 17.1.3

xiaoyuvax avatar Apr 11 '22 03:04 xiaoyuvax

I finally was able to get something from the diagnostic messages:

[CodeMaid Handled Exception 07:38:06 PM] CodeMaid Cleanup for '*****Controller.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.<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

brogdonm avatar Apr 24 '22 01:04 brogdonm

That most recent call stack error message I believe is fixed in the upcoming version. You can check the VS2022 CI build here to see if it helps. https://www.vsixgallery.com/extension/9079e73d-3fbb-4e07-8dab-f44fa5d8e8b5

codecadwallader avatar May 03 '22 12:05 codecadwallader

Now the maid is back, thx.

xiaoyuvax avatar May 13 '22 08:05 xiaoyuvax

Hi there. Just updated to VS2022, installed the extension and got this exception:

[CodeMaid Handled Exception 09:54:33 PM] CodeMaid Cleanup for 'DebugStuff.cs' was stopped: System.ArgumentException: startingPosition (14139) must lie inside searchRange ([0..14138))
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.<>c__DisplayClass4_0.<TryFindNextMatch>b__0() in C:\projects\codemaid\CodeMaidShared\Helpers\TextDocumentHelper.cs:line 130
   at SteveCadwallader.CodeMaid.Helpers.TextDocumentHelper.<>c__DisplayClass20_0.<<RunOnUIThread>b__0>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.<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

LVNov avatar Jul 17 '22 18:07 LVNov

Hi there. Just updated to VS2022, installed the extension and got this exception:

[CodeMaid Handled Exception 09:54:33 PM] CodeMaid Cleanup for 'DebugStuff.cs' was stopped: System.ArgumentException: startingPosition (14139) must lie inside searchRange ([0..14138))
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.<>c__DisplayClass4_0.<TryFindNextMatch>b__0() in C:\projects\codemaid\CodeMaidShared\Helpers\TextDocumentHelper.cs:line 130
   at SteveCadwallader.CodeMaid.Helpers.TextDocumentHelper.<>c__DisplayClass20_0.<<RunOnUIThread>b__0>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.<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

Just pop over to Devexpress and download its CODERUSH. It's now free and will do everything that you need. I am afraid that Codemaid has been on shaky ground ever since VS 2022 got released. See link: https://www.devexpress.com/

Duelbat avatar Jul 18 '22 00:07 Duelbat

@Duelbat thanks, but I'm a faithful CodeMaid user.

@codecadwallader hey man, is there any update on the situation? Can I help somehow?

LVNov avatar Jul 20 '22 16:07 LVNov

@LVNov I was also a very faithful user of CodeMaid in VS 2019. But code clean up was a mandatory feature. It does not work in 2022. So Devexpress to to the resuce.

Duelbat avatar Jul 20 '22 20:07 Duelbat

I was having problems where CodeMaid was not able to cleanup projects if I rich click clean. But it was able to clean up single files on save. After some trial and error, I found out that removing the file header in the Update portion of the Options fixed the problem. I'm now able to clean all the files in a project at once. The error I was getting was: image

lolodi avatar Apr 11 '23 17:04 lolodi

It happened when I wrapped it in a preprocessor to briefly backup the code I was working on.

For example.

#if backup
//backups
#else
//Error here?
#endif

Leuconoe avatar Jun 13 '23 23:06 Leuconoe

The issue still persists on CodeMaid v12.0.300 on Visual Studio 2022 v17.8.4.

OculiViridi avatar Jan 12 '24 15:01 OculiViridi

The issue also happens in VS 2022 Version 17.9.6

fdrumondwoolworths avatar May 06 '24 23:05 fdrumondwoolworths