belav / csharpier

CSharpier is an opinionated code formatter for c#.
https://csharpier.com
MIT License
1.4k stars 97 forks source link

Visual Studio 17.8.0 hangs with version 1.4.8 #1026

Open danielcandea opened 11 months ago

danielcandea commented 11 months ago

I did a fresh install of Windows 11 build 22621.2715, installed CSharpier plugin 1.4.8 and Visual Studio hangs after a few seconds after opening a solution.

I can reproduce this every time with CSharpier being the only plugin installed. Once I uninstall it and add my usual ones everything works fine.

belav commented 11 months ago

If you are using CSharpier 0.26.* (which would happen if you are clicking install globally/locally) then this is probably the same issue that is occurring across all of the IDEs. I'm hoping to be able to track it down soon.

As a workaround you can install csharpier 0.25.0 outside of the plugin.

belav commented 11 months ago

I have a few questions, I think most other people are experiencing complete freezes that VS doesn't recover from.

Does VS go back to normal after a few seconds or is it a complete freeze? Does switching to 0.25.0 make the problem go away. Are you able to format any files? Could you share what is in the output window for CSharpier? Turning on log debug messages first will give more info.

danielcandea commented 11 months ago

VS doesn't recover, it remains like that. But it isn't like "Not Responding" freeze, being greyed out, more like there is an invisible dialog window preventing clicks and scrolling. Clicking VS icon in the taskbar doesn't do anything either.

I can't do anything past VS opening the solution, not seeing output, not opening a file or format an existing one. The only way to uninstall the plugin was to open VS without code.

I downgraded to 0.25.0 and the plugin seems fine again.

belav commented 11 months ago

I believe I know a way to resolve the problem, see https://github.com/belav/csharpier/issues/926#issuecomment-1817939428 for more details

danielcandea commented 11 months ago

That didn't solve the issue, but while going through issue I saw that duplicate lines in .editorconfig might cause problems so I checked it and had some duplicates. I removed them and things seem fine now, csharpier installed globally, v0.26.2 and the VS plugin v1.4.8.

IT-CASADO commented 11 months ago

I'm facing the same issue with v0.26.2 and the VS plugin v1.4.8. My .editorconfig doesn't have any duplicates and the mentioned workarond by @belav doesn't help.

This ticket should be re-opened.

IT-CASADO commented 11 months ago

Seems to be fixed with version v0.26.3 :)

IT-CASADO commented 10 months ago

This is not fixed. VS hangs regularly on my machine and for colleagues.

If that happens I can see CPU spikes forced by CSharpier:

image

If I wait for a long time (or kill the CSharpier task in Task Manager) I'm ending with #1072. This is very frustrating.

I tried the troubleshooting guide multiple times, but it doesn't help.

This is from log:

Starting
CSharpier process appears to be hung, restarting it.
CSharpier process appears to be hung, restarting it.
CSharpier process appears to be hung, restarting it.
CSharpier process appears to be hung, restarting it.
CSharpier process appears to be hung, restarting it.
CSharpier process appears to be hung, restarting it.
CSharpier process appears to be hung, restarting it.
CSharpier process appears to be hung, restarting it.
CSharpier process appears to be hung, restarting it.
CSharpier process appears to be hung, restarting it.
CSharpier process appears to be hung, restarting it.
CSharpier process appears to be hung, restarting it.
CSharpier process appears to be hung, restarting it.
CSharpier process appears to be hung, restarting it.
CSharpier process appears to be hung, restarting it.
CSharpier process appears to be hung, restarting it.
CSharpier process appears to be hung, restarting it.
CSharpier process appears to be hung, restarting it.
CSharpier process appears to be hung, restarting it.
CSharpier process appears to be hung, restarting it.
CSharpier process appears to be hung, restarting it.
CSharpier process appears to be hung, restarting it.
CSharpier process appears to be hung, restarting it.
CSharpier process appears to be hung, restarting it.
CSharpier process appears to be hung, restarting it.
CSharpier process appears to be hung, restarting it.
CSharpier process appears to be hung, restarting it.
CSharpier process appears to be hung, restarting it.
CSharpier process appears to be hung, restarting it.
CSharpier process appears to be hung, restarting it.

And VS is showing me:

image
danielcandea commented 10 months ago

Started happening again, slightly differently for me as well, every time I open Visual Studio I get a message that it stopped responding for about 15-20 seconds, afterwards it seems fine. I am using Visual Studio 17.8.3, plugin 1.4.8 and the tool is at 0.26.6.

IT-CASADO commented 10 months ago

For me sometimes it's still working after the 'stopped responding' message.

I very often open Visual Studio and VS Studio Code at the same time. I think in this case CSharpier is broken in Visual Studio after the message. But this is only a feeling...

In Visual Studio Code I don't get any issues so far.

Kurren123 commented 10 months ago

Happening to me too. No .editorconfig file, I enable debug log messages and get this:

Starting
Ensure there is a csharpier process for C:\dev\PBI-SQLService
Looking for C:\dev\PBI-SQLService\.config/dotnet-tools.json
Looking for C:\dev\.config/dotnet-tools.json
Looking for C:\.config/dotnet-tools.json
Unable to find dotnet-tools.json, falling back to running dotnet csharpier --version
dotnet csharpier --version output: 0.26.7+c8aec144f227bda8cf195011e9d91bb36c33337f
Removing everything after + to use 0.26.7
dotnet csharpier --version output: 0.26.7+c8aec144f227bda8cf195011e9d91bb36c33337f
Adding new version 0.26.7 process for C:\dev\PBI-SQLService
Warm CSharpier with initial format
CSharpier process appears to be hung, restarting it.
Warm CSharpier with initial format
belav commented 10 months ago

I resolved a number of issues with the new 1.5.0 version of the extension. It also has better logging and notification when it is unable to start the CSharpier process.

Let me know if there are still issues!

danielcandea commented 10 months ago

I've updated the plugin to 1.5.0 with the tool at 0.26.6 and had no issues after opening a few solutions. Next, I've updated the tool to 0.26.7 and got one hang after opening a solution, but couldn't reproduce it afterwards after several tries.

Kurren123 commented 10 months ago

I resolved a number of issues with the new 1.5.0 version of the extension. It also has better logging and notification when it is unable to start the CSharpier process.

Let me know if there are still issues!

Thanks so much, it no longer hangs (extension version 1.5.0, tool version 0.26.7). However I am getting this on every load of visual studio:

[Info - 17/12/2023 23:17:15] Starting
[Error - 17/12/2023 23:17:16] System.NullReferenceException: Object reference not set to an instance of an object.
   at CSharpier.VisualStudio.ReformatWithCSharpierOnSave.FindDocument(UInt32 docCookie)
IT-CASADO commented 10 months ago

In general this seems to work now :)

Visual Studio is not hanging for a long time, but I still get this message: "Visual Studio stopped responding for x seconds"

image

But everything is working so far.

In the log I can see a warning ("CSharpier process appears to be hung, restarting it.") and sometimes an error ("Object reference not set to an instance of an object."):

My Log:

[Info - 19.12.2023 08:59:57] Starting
[Debug - 19.12.2023 08:59:58] Ensure there is a csharpier process for xxx/Report\Service\Evo.ReportEngine.Service.Job
[Debug - 19.12.2023 08:59:58] Looking for xxx/Report\Service\Evo.ReportEngine.Service.Job\.config/dotnet-tools.json
[Debug - 19.12.2023 08:59:58] Looking for xxx/Report\Service\.config/dotnet-tools.json
[Debug - 19.12.2023 08:59:58] Looking for xxx/Report\.config/dotnet-tools.json
[Debug - 19.12.2023 08:59:58] Looking for xxx/.config/dotnet-tools.json
[Debug - 19.12.2023 08:59:58] Looking for xxx\.config/dotnet-tools.json
[Debug - 19.12.2023 08:59:58] Found version 0.26.7 in xxx\.config/dotnet-tools.json
[Debug - 19.12.2023 08:59:59] dotnet csharpier --version output: 0.26.7+c8aec144f227bda8cf195011e9d91bb36c33337f
[Debug - 19.12.2023 08:59:59] Using 0.26.7 as the version number.
[Debug - 19.12.2023 08:59:59] CSharpier at C:\Users\CasadoDaniel\AppData\Local\CSharpier\0.26.7 already exists
[Debug - 19.12.2023 08:59:59] Adding new version 0.26.7 process for xxx/Report\Service\Evo.ReportEngine.Service.Job
[Debug - 19.12.2023 08:59:59] Warm CSharpier with initial format
[Warn - 19.12.2023 09:00:02] CSharpier process appears to be hung, restarting it.
[Warn - 19.12.2023 09:00:05] CSharpier process appears to be hung, restarting it.
cture
[Error - 19.12.2023 09:00:51] System.NullReferenceException: Object reference not set to an instance of an object.
   at CSharpier.VisualStudio.ReformatWithCSharpierOnSave.FindDocument(UInt32 docCookie)
belav commented 10 months ago

I believe I have the occasional NRE fixed and am releasing 1.5.1 for that.

The initial hang some people are seeing is probably csharpier being installed in the background. I think this could be avoided by converting a lot of this code to async, but it should be only occuring once when using a new version of csharpier so I'm not sure it is worth the effort.

I've managed to reproduce getting CSharpier to hang and restart itself.

Rider had a similar problem, but the fix in Rider (java based) doesn't seem to apply to VS. I'll dig into that a bit more.

@IT-CASADO are you seeing the "Visual Studio stopped responding for X seconds" message regularly? It also seems like the initial warming of csharpier is hanging for you, which I have not seem before. The warming process is a simple c# class, so I can't see why it would be causing things to hang.

I do have a reworking of the communication between the extensions and csharpier using GRPC almost ready, and I am hoping that will resolve some of the flakeiness with piping input/output to csharpier.

parched commented 10 months ago

I've been getting this a bit recently. I'm not sure exactly when it triggers, but I think it's when there is compilation errors. image

mejobloggs commented 9 months ago

I've been getting this a bit recently. I'm not sure exactly when it triggers, but I think it's when there is compilation errors. image

Same here, I get this most times I open Visual Studio

ceisele-r commented 9 months ago

For me, it's happening every time I open Visual Studio and afterwards open a C# file in the solution.

So to reproduce:

  1. open a Visual Studio C# solution -> all good for now.
  2. Then open a C# file, Visual Studio hangs for 10-20 Seconds and the yellow bar appears.

In contrast to @parched 's assumption, there are no compile errors in my solution.