belav / csharpier

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

Visual Studio stopped responding for 9 seconds. Disabling the extension CSharpier 1.5.1 might help. #1182

Open mejobloggs-cw opened 9 months ago

mejobloggs-cw commented 9 months ago

Multiple times a day I get this message. "Visual Studio stopped responding for 9 seconds. Disabling the extension CSharpier 1.5.1 might help."

Here is the CSharpier output:

[Debug - 19/02/2024 2:45:29 pm] dotnet csharpier --version output: 0.27.2+b456544aad8957d0e2026afe1a37544bb74552ba
[Debug - 19/02/2024 2:45:29 pm] Using 0.27.2 as the version number.
[Debug - 19/02/2024 2:45:29 pm] CSharpier at C:\Users\myusername\AppData\Local\CSharpier\0.27.2 already exists
[Debug - 19/02/2024 2:45:29 pm] Adding new version 0.27.2 process for C:\Projects\Blah\Blah
[Debug - 19/02/2024 2:45:29 pm] Warm CSharpier with initial format
[Warn - 19/02/2024 2:45:32 pm] CSharpier process appears to be hung, restarting it.
[Warn - 19/02/2024 2:45:35 pm] CSharpier process appears to be hung, restarting it.

Visual Studio info

Microsoft Visual Studio Community 2022
Version 17.10.0 Preview 1.0
VisualStudio.17.Preview/17.10.0-pre.1.0+34607.79
Microsoft .NET Framework
Version 4.8.09032

Installed Version: Community

ASP.NET and Web Tools   17.10.43.40073
ASP.NET and Web Tools

Azure App Service Tools v3.0.0   17.10.43.40073
Azure App Service Tools v3.0.0

BlazmExtension   1.7.8
Extension that helps you with common Blazor tasks like creating a Isolated CSS or JavaScript from a context menu item

C# Tools   4.10.0-1.24081.13+fa72fa61b0d822ea8a3fbeb96f668340419ab5cd
C# components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used.

Common Azure Tools   1.10
Provides common services for use by Azure Mobile Services and Microsoft Azure Tools.

Editor Bar   1.0.4
Editor bar - bar for the text editor, highlighting parent project of the opened document.

Entity Framework Core Power Tools   2.6
Adds useful design-time EF Core DbContext features to the Visual Studio Solution Explorer context menu.

Insert Guid   1.3.6
Makes it super easy to insert a new GUID into any editor and input field

Microsoft JVM Debugger   1.0
Provides support for connecting the Visual Studio debugger to JDWP compatible Java Virtual Machines

NuGet Package Manager   6.10.0
NuGet Package Manager in Visual Studio. For more information about NuGet, visit https://docs.nuget.org/

Object Dumper   0.0.0.96
Extension for exporting in-memory objects during debugging to C#, JSON, VB, XML, and YAML string. For more information, visit https://github.com/ycherkes/ObjectDumper

Razor (ASP.NET Core)   17.10.1.2407905+d09e369ed8364c3be1d7f2aa4c8626415045f023
Provides languages services for ASP.NET Core Razor.

SQL Server Data Tools   17.10.31.0
Microsoft SQL Server Data Tools

Tweaks 2022   1.1.143
A collection of minor fixes and tweaks for Visual Studio to reduce the paper cuts and make you a happier developer

TypeScript Tools   17.0.30131.2001
TypeScript Tools for Microsoft Visual Studio

Visual Basic Tools   4.10.0-1.24081.13+fa72fa61b0d822ea8a3fbeb96f668340419ab5cd
Visual Basic components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used.

Visual F# Tools   17.10.0-beta.24079.8+7c217c487c6e2b7d824f3d40666b3cbad412cad4
Microsoft Visual F# Tools

Visual Studio IntelliCode   2.2
AI-assisted development for Visual Studio.
belav commented 9 months ago

I released a new version of the extension today that I hope will address these problems, or at least make them easier to track down.

The latest (1.5.2) version has a new option "Use CSharpier Server", could you try the new version with that on to see if it resolves the issue?

You'll get a windows firewall popup about dotnet-csharpier needing internet access, which it doesn't. The extension communicates with the cli over http with this new version. I resolved the firewall warning in that in #1184 but it hasn't been released yet.

mejobloggs-cw commented 9 months ago

It's still happening, but there's a lot more logs now.

This is without the new "Use CSharpier Server" option enabled

[Info - 20/02/2024 9:41:06 am] Starting
[Debug - 20/02/2024 9:41:39 am] Ensure there is a csharpier process for E:\Blah\Blah\Blah
[Debug - 20/02/2024 9:41:39 am] Looking for E:\Blah\Blah\Blah\.config/dotnet-tools.json
[Debug - 20/02/2024 9:41:39 am] Looking for E:\Blah\Blah\.config/dotnet-tools.json
[Debug - 20/02/2024 9:41:39 am] Looking for E:\Blah\.config/dotnet-tools.json
[Debug - 20/02/2024 9:41:39 am] Looking for E:\.config/dotnet-tools.json
[Debug - 20/02/2024 9:41:39 am] Unable to find dotnet-tools.json, falling back to running dotnet csharpier --version
[Debug - 20/02/2024 9:41:41 am] dotnet csharpier --version output: 0.27.3
[Debug - 20/02/2024 9:41:41 am] Using 0.27.3 as the version number.
[Debug - 20/02/2024 9:41:41 am] dotnet csharpier --version output: 0.27.3
[Debug - 20/02/2024 9:41:41 am] Using 0.27.3 as the version number.
[Debug - 20/02/2024 9:41:41 am] CSharpier at C:\Users\MyUserName\AppData\Local\CSharpier\0.27.3 already exists
[Debug - 20/02/2024 9:41:41 am] Adding new version 0.27.3 process for E:\Blah\Blah\Blah
[Debug - 20/02/2024 9:41:41 am] Warm CSharpier with initial format
[Warn - 20/02/2024 9:41:44 am] CSharpier process appears to be hung, restarting it.
[Warn - 20/02/2024 9:41:47 am] CSharpier process appears to be hung, restarting it.
[Debug - 20/02/2024 9:41:47 am] Ensure there is a csharpier process for E:\Blah\Blah\Blah
[Debug - 20/02/2024 9:41:47 am] Ensure there is a csharpier process for E:\Blah\Blah\Blah

I will try the Server option now....

Here is the logs with Server option also. I have no Visual Studio warning using Server option:

[Info - 20/02/2024 9:51:27 am] Starting
[Debug - 20/02/2024 9:51:27 am] Ensure there is a csharpier process for E:\Blah\Blah\Blah
[Debug - 20/02/2024 9:51:27 am] Looking for E:\Blah\Blah\Blah\.config/dotnet-tools.json
[Debug - 20/02/2024 9:51:27 am] Looking for E:\Blah\Blah\.config/dotnet-tools.json
[Debug - 20/02/2024 9:51:27 am] Looking for E:\Blah\.config/dotnet-tools.json
[Debug - 20/02/2024 9:51:27 am] Looking for E:\.config/dotnet-tools.json
[Debug - 20/02/2024 9:51:27 am] Unable to find dotnet-tools.json, falling back to running dotnet csharpier --version
[Debug - 20/02/2024 9:51:28 am] dotnet csharpier --version output: 0.27.3
[Debug - 20/02/2024 9:51:28 am] Using 0.27.3 as the version number.
[Debug - 20/02/2024 9:51:28 am] dotnet csharpier --version output: 0.27.3
[Debug - 20/02/2024 9:51:28 am] Using 0.27.3 as the version number.
[Debug - 20/02/2024 9:51:28 am] CSharpier at C:\Users\MyUserName\AppData\Local\CSharpier\0.27.3 already exists
[Debug - 20/02/2024 9:51:28 am] Adding new version 0.27.3 process for E:\Blah\Blah\Blah
[Debug - 20/02/2024 9:51:28 am] Connecting via port 49154
[Debug - 20/02/2024 9:51:28 am] Warm CSharpier with initial format
[Debug - 20/02/2024 9:51:38 am] Ensure there is a csharpier process for E:\Blah\Blah\Blah
mejobloggs-cw commented 9 months ago

I just got over a full minute hang on reformat using the Server option. Here's the log


[Debug - 20/02/2024 2:13:43 pm] Ensure there is a csharpier process for E:\Blah\Blah
[Debug - 20/02/2024 2:14:43 pm] OnBeforeSave
[Debug - 20/02/2024 2:14:43 pm] No RunOnSave
[Debug - 20/02/2024 2:14:54 pm] OnBeforeSave
[Debug - 20/02/2024 2:14:54 pm] No RunOnSave
[Debug - 20/02/2024 2:15:53 pm] OnBeforeSave
[Debug - 20/02/2024 2:15:53 pm] No RunOnSave
[Info - 20/02/2024 2:15:57 pm] Formatting started for E:\Blah\Startup.cs.
[Warn - 20/02/2024 2:17:37 pm] Failed posting to the csharpier server. System.Net.WebException: The operation has timed out
   at System.Net.HttpWebRequest.GetResponse()
   at CSharpierProcessServer.FormatFile(String content, String filePath)
[Info - 20/02/2024 2:17:37 pm] Formatted in 100021ms
[Debug - 20/02/2024 2:17:37 pm] Skipping write because result is empty
[Debug - 20/02/2024 2:17:37 pm] OnBeforeSave
[Debug - 20/02/2024 2:17:37 pm] No RunOnSave
[Debug - 20/02/2024 2:17:43 pm] Ensure there is a csharpier process for E:\Blah\Blah
[Debug - 20/02/2024 2:17:45 pm] OnBeforeSave
[Debug - 20/02/2024 2:17:45 pm] No RunOnSave
mejobloggs-cw commented 9 months ago

Ok yeah, still getting the "Visual Studio stopped responding" message sometimes while using the Server option.

"Visual Studio stopped responding for 7 seconds. Disabling the extension CSharpier 1.5.2 might help. Disable this extension Manage performance Don't report this extension again "

[Info - 21/02/2024 10:43:47 am] Starting
[Error - 21/02/2024 10:43:59 am] System.ArgumentException: The parameter is incorrect. (Exception from HRESULT: 0x80070057 (E_INVALIDARG))
   at EnvDTE.Documents.Item(Object index)
   at CSharpier.VisualStudio.ReformatWithCSharpierOnSave.FindDocument(UInt32 docCookie)
[Debug - 21/02/2024 10:44:00 am] Ensure there is a csharpier process for E:\Blah\Blah\Blah
[Debug - 21/02/2024 10:44:00 am] Looking for E:\Blah\Blah\Blah\.config/dotnet-tools.json
[Debug - 21/02/2024 10:44:00 am] Looking for E:\Blah\Blah\.config/dotnet-tools.json
[Debug - 21/02/2024 10:44:00 am] Looking for E:\Blah\.config/dotnet-tools.json
[Debug - 21/02/2024 10:44:00 am] Looking for E:\.config/dotnet-tools.json
[Debug - 21/02/2024 10:44:00 am] Unable to find dotnet-tools.json, falling back to running dotnet csharpier --version
[Debug - 21/02/2024 10:44:02 am] dotnet csharpier --version output: 0.27.3
[Debug - 21/02/2024 10:44:02 am] Using 0.27.3 as the version number.
[Debug - 21/02/2024 10:44:02 am] dotnet csharpier --version output: 0.27.3
[Debug - 21/02/2024 10:44:02 am] Using 0.27.3 as the version number.
[Debug - 21/02/2024 10:44:02 am] CSharpier at C:\Users\MyUserName\AppData\Local\CSharpier\0.27.3 already exists
[Debug - 21/02/2024 10:44:02 am] Adding new version 0.27.3 process for E:\Blah\Blah\Blah
[Debug - 21/02/2024 10:44:04 am] Connecting via port 49160
[Debug - 21/02/2024 10:44:04 am] Warm CSharpier with initial format
belav commented 8 months ago

I'm thinking there is either something in some of your files that csharpier can't handle. If it is all files in the project, then maybe something in an .editorconfig.

If you create a new file with a basic class in your project, can that be formatted? Are you able to share the contents of the project? If you run dotnet csharpier . in the project, does that work?

mejobloggs-cw commented 8 months ago

I created a new "ASP.NET Core Web API" project with Identity.

Closed VS, opened the project, and got the error again "Visual Studio stopped responding for 9 seconds. Disabling the extension CSharpier 1.5.2"

So it's not the code from my other project or editorconfig. I double checked and no editorconfig is present in the new webapp

[Info - 26/02/2024 11:07:38 am] Starting
[Debug - 26/02/2024 11:07:38 am] Ensure there is a csharpier process for E:\source\WebApplication2\WebApplication2
[Debug - 26/02/2024 11:07:38 am] Looking for E:\source\WebApplication2\WebApplication2\.config/dotnet-tools.json
[Debug - 26/02/2024 11:07:38 am] Looking for E:\source\WebApplication2\.config/dotnet-tools.json
[Debug - 26/02/2024 11:07:38 am] Looking for E:\source\.config/dotnet-tools.json
[Debug - 26/02/2024 11:07:38 am] Looking for E:\.config/dotnet-tools.json
[Debug - 26/02/2024 11:07:38 am] Unable to find dotnet-tools.json, falling back to running dotnet csharpier --version
[Debug - 26/02/2024 11:07:39 am] dotnet csharpier --version output: 0.27.3
[Debug - 26/02/2024 11:07:39 am] Using 0.27.3 as the version number.
[Debug - 26/02/2024 11:07:39 am] dotnet csharpier --version output: 0.27.3
[Debug - 26/02/2024 11:07:39 am] Using 0.27.3 as the version number.
[Debug - 26/02/2024 11:07:39 am] CSharpier at C:\Users\MyUser\AppData\Local\CSharpier\0.27.3 already exists
[Debug - 26/02/2024 11:07:39 am] Adding new version 0.27.3 process for E:\source\WebApplication2\WebApplication2
[Debug - 26/02/2024 11:07:39 am] Warm CSharpier with initial format
[Warn - 26/02/2024 11:07:42 am] CSharpier process appears to be hung, restarting it.
[Warn - 26/02/2024 11:07:45 am] CSharpier process appears to be hung, restarting it.
[Debug - 26/02/2024 11:07:45 am] Ensure there is a csharpier process for E:\source\WebApplication2\WebApplication2
belav commented 8 months ago

The logging from the extension side doesn't really give me any indication of what the problem is. I hope to add logging to the csharpier side, but I don't know how soon that will happen.

The only other thing I can think of is for you to debug csharpier.

mejobloggs-cw commented 8 months ago

I'll give it a try but the issue usually doesn't happen when I format a file, it usually happens when I first open Visual Studio.

So I think the method of attaching to a process is too late because I think the issue is in the process start/warmup

Also I notice in Task Manager one dotnet-csharpier.exe starts for each Visual Studio instance. But when I close Visual Studio, dotnet-csharpier process still exists.

As of right now I have 0 Visual Studio open, but 5 dotnet-csharpier in Task Manager.

Perhaps this is intended behaviour to make next launch faster, not sure, just thought I'd mention it

parched commented 2 months ago

@belav I get this too every time I open VS, image

We're using 0.28.2 in this project.

How should I go about investigating the issue?