codemaid
codemaid copied to clipboard
Checking "automatically run cleanup on file save" causes CSHTML file to not save.
Environment
- Visual Studio version: 2022 Professional
- CodeMaid version: 12.0
- Code language: HTML, C#
Description
I checked the box in the options to "automatically run cleanup on file save". Then I go into my CSHTML file, make some formatting changes, and save the file. The formatting changes happen, but the file remains unsaved. Or perhaps the save is causing a change to occur after the format completes and saves. This seems to be unique to CSHTML files, going to my CS files the save/cleanup works as expected.
Steps to recreate
- Create CSHTML file.
- Create some poorly formatted HTML markup.
- Enable "automatically run cleanup on file save" in the CodeMaid options.
- Save CSHTML file.
Current behavior
The file saves, but I think it is modified after the save in some way, and the IDE puts an * in the VS tab indicating the file has content to save. The images below are the before and after of saving the file with no additional edits on my part. I put a poorly formatted label tag in the file, CodeMaid fixed it correctly, but it leaves unsaved modifications after the save happens. The tab in the resulting image shows the file is modified. The * flashed, so it appears that CodeMaid saved the file, and time stamp on the file suggests this is the case. I'm thinking CodeMaid must be altering the file after the save happens.


Expected behavior
The file should format itself, and save, and not have any further edits to the file.
Thanks for reporting the issue. I have been able to reproduce it. I've looked at the CodeMaid diagnostics panel and confirmed the save event is only being triggered and executing once. I'm not sure what other behavior is kicking in after that event to cause it to modify further.
@codecadwallader I have recently seen a related issue on plain .CS files. What I've seen is:
- have "automatically run cleanup on file save" enabled on the Code Main extension
- Modify an exisitng .CS file
- Save the file
- OUTCOME: file is saved correctly, but automatically set to an unsaved state in VS
I'm seeing the exact same behavior as @codecadwallader
I have not been able to reproduce the issue with C# files (using VS 17.4.0 Preview 2.1). Is it possible you have any other extensions installed that may also be triggered on save events?
It's happening to me and to another collegue (plain CS). VS2022 + CodeMaid + XAML Styler and the default set of extensions (Live share, ML.NET, Xamarin, ..)
I have the same problem VS 17.3.5. I disabled all extras except xaml styler. When I turn on code maid, files stop saving. Only on manual closing the file modal window appear with question. For me, this is a fatal error because it is impossible to work and debug normally.

I have had the same experience as cklogs.
This same save behavior has affected .cs files and .xaml files for me.
I have the same issue with cs files. Hope it will get fixed soon.
Same issue with cs files. I'm using VS Enterprise 2022 (64-bit) Version 17.3.6 and CodeMaid Version 12.0.300
Same on every file in solution
Same issue here
Visual Studio 2022 v17.3.2 Project: Net Framework 4.8 Codemaid v12.0.300
Tried disabling every extension i have installed, only the moment codemaid is enabled does the issue occure. Happens in both .cs and .cshtml files (not tried other file types)
Thanks all for chiming in.
I was previously able to reproduce the issue with .cshtml but not .cs or .xaml.
I am no longer able to reproduce the issue in .cshtml files (nor other file types) using the latest preview version of Visual Studio 2022 v17.4.0 Preview 6.0. Can anyone who is regularly seeing the issue try the latest version of Visual Studio to see if it resolves it for them as well?
Thanks all for chiming in.
I was previously able to reproduce the issue with .cshtml but not .cs or .xaml.
I am no longer able to reproduce the issue in .cshtml files (nor other file types) using the latest preview version of Visual Studio 2022 v17.4.0 Preview 6.0. Can anyone who is regularly seeing the issue try the latest version of Visual Studio to see if it resolves it for them as well?
Today I've updated my Visual Studio to the lastest version v17.4.0 and I'm not having the issue with the .cs files, now I'm able to use the Automatic Cleaup On Save without issues.
After using this for a while it does seem to be fixed for me as well. Thanks for the help!
As @ernestfolch says, I couldn't reproduce it too after update