Rider plugin does not reformat .cs files
I have installed version 1.3.7 of the plugin and upon saving any .cs file in Rider, the error below generates and the file is not formatted. This error also generates if I manually initiate a format through the "Reformat with CSharpier" action in the Rider action menu.
Exception in plugin CSharpier (1.3.7)
java.io.IOException: The pipe is being closed
at java.base/java.io.FileOutputStream.writeBytes(Native Method)
at java.base/java.io.FileOutputStream.write(FileOutputStream.java:349)
at java.base/java.io.BufferedOutputStream.flushBuffer(BufferedOutputStream.java:81)
at java.base/java.io.BufferedOutputStream.write(BufferedOutputStream.java:122)
at java.base/sun.nio.cs.StreamEncoder.writeBytes(StreamEncoder.java:234)
at java.base/sun.nio.cs.StreamEncoder.implWrite(StreamEncoder.java:304)
at java.base/sun.nio.cs.StreamEncoder.implWrite(StreamEncoder.java:282)
at java.base/sun.nio.cs.StreamEncoder.write(StreamEncoder.java:132)
at java.base/sun.nio.cs.StreamEncoder.write(StreamEncoder.java:142)
at java.base/java.io.OutputStreamWriter.write(OutputStreamWriter.java:223)
at java.base/java.io.Writer.write(Writer.java:249)
at com.intellij.csharpier.CSharpierProcessPipeMultipleFiles.formatFile(CSharpierProcessPipeMultipleFiles.java:50)
at com.intellij.csharpier.FormattingService.format(FormattingService.java:58)
at com.intellij.csharpier.ReformatWithCSharpierAction.processFileInEditor(ReformatWithCSharpierAction.java:52)
at com.intellij.csharpier.ReformatWithCSharpierAction.actionPerformed(ReformatWithCSharpierAction.java:24)
at com.intellij.openapi.actionSystem.ex.ActionUtil.doPerformActionOrShowPopup(ActionUtil.java:333)
at com.intellij.ide.actions.GotoActionAction.lambda$performActionImpl$4(GotoActionAction.java:90)
at com.intellij.openapi.actionSystem.ex.ActionUtil.performDumbAwareWithCallbacks(ActionUtil.java:356)
at com.intellij.ide.actions.GotoActionAction.performActionImpl(GotoActionAction.java:89)
at com.intellij.ide.actions.GotoActionAction.lambda$performAction$2(GotoActionAction.java:69)
at com.intellij.openapi.application.TransactionGuardImpl.runWithWritingAllowed(TransactionGuardImpl.java:209)
at com.intellij.openapi.application.TransactionGuardImpl.access$100(TransactionGuardImpl.java:21)
at com.intellij.openapi.application.TransactionGuardImpl$1.run(TransactionGuardImpl.java:191)
at com.intellij.openapi.application.impl.ApplicationImpl.runIntendedWriteActionOnCurrentThread(ApplicationImpl.java:831)
at com.intellij.openapi.application.impl.ApplicationImpl$3.run(ApplicationImpl.java:456)
at com.intellij.openapi.application.impl.FlushQueue.doRun(FlushQueue.java:79)
at com.intellij.openapi.application.impl.FlushQueue.runNextEvent(FlushQueue.java:122)
at com.intellij.openapi.application.impl.FlushQueue.flushNow(FlushQueue.java:41)
at java.desktop/java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:318)
at java.desktop/java.awt.EventQueue.dispatchEventImpl(EventQueue.java:788)
at java.desktop/java.awt.EventQueue$3.run(EventQueue.java:739)
at java.desktop/java.awt.EventQueue$3.run(EventQueue.java:731)
at java.base/java.security.AccessController.doPrivileged(AccessController.java:399)
at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:86)
at java.desktop/java.awt.EventQueue.dispatchEvent(EventQueue.java:758)
at com.intellij.ide.IdeEventQueue.defaultDispatchEvent(IdeEventQueue.kt:666)
at com.intellij.ide.IdeEventQueue._dispatchEvent$lambda$7(IdeEventQueue.kt:570)
at com.intellij.openapi.application.impl.ApplicationImpl.withoutImplicitRead(ApplicationImpl.java:1446)
at com.intellij.ide.IdeEventQueue._dispatchEvent(IdeEventQueue.kt:570)
at com.intellij.ide.IdeEventQueue.access$_dispatchEvent(IdeEventQueue.kt:68)
at com.intellij.ide.IdeEventQueue$dispatchEvent$processEventRunnable$1$1$1.compute(IdeEventQueue.kt:349)
at com.intellij.ide.IdeEventQueue$dispatchEvent$processEventRunnable$1$1$1.compute(IdeEventQueue.kt:348)
at com.intellij.openapi.progress.impl.CoreProgressManager.computePrioritized(CoreProgressManager.java:787)
at com.intellij.ide.IdeEventQueue$dispatchEvent$processEventRunnable$1$1.invoke(IdeEventQueue.kt:348)
at com.intellij.ide.IdeEventQueue$dispatchEvent$processEventRunnable$1$1.invoke(IdeEventQueue.kt:343)
at com.intellij.ide.IdeEventQueueKt.performActivity$lambda$1(IdeEventQueue.kt:994)
at com.intellij.openapi.application.TransactionGuardImpl.performActivity(TransactionGuardImpl.java:105)
at com.intellij.ide.IdeEventQueueKt.performActivity(IdeEventQueue.kt:994)
at com.intellij.ide.IdeEventQueue.dispatchEvent$lambda$4(IdeEventQueue.kt:343)
at com.intellij.openapi.application.impl.ApplicationImpl.runIntendedWriteActionOnCurrentThread(ApplicationImpl.java:831)
at com.intellij.ide.IdeEventQueue.dispatchEvent(IdeEventQueue.kt:385)
at java.desktop/java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:207)
at java.desktop/java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:128)
at java.desktop/java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:117)
at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:113)
at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:105)
at java.desktop/java.awt.EventDispatchThread.run(EventDispatchThread.java:92)
JetBrains Rider 2023.1.1
Build #RD-231.8770.54, built on April 25, 2023
Runtime version: 17.0.6+10-b829.9 amd64
VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o.
Windows 11.0
.NET 7.0.2 (Server GC)
GC: G1 Young Generation, G1 Old Generation
Memory: 1500M
Cores: 20
Registry:
ide.experimental.ui=true
vcs.empty.toolwindow.show=false
ide.new.project.model.index.case.sensitivity=true
database.show.search.tab=false
rider.enable.designer.winForms=false
rdclient.asyncActions=false
Non-Bundled Plugins:
com.intellij.csharpier (1.3.7)
unreal-link (2023.1.0.281)
com.jetbrains.rider.android (231.8770.54)
intellij.prettierJS (231.8770.67)
Could you check the rider logs too see what kind of CSharpier logging occurs when Rider starts? I'm thinking something is failing earlier and it leaves CSharpier in a non-working state which throws this exception.
Enabling the debug logging will give more info. https://github.com/belav/csharpier/tree/main/Src/CSharpier.Rider#troubleshooting
Thanks. I did that and I believe I found the issue. I will attempt to install .NET version 6 to see if that resolves the problem, but is this an expected requirement and would it be possible to list it as a dependency somehow so that Rider knows to automatically install it?
2023-05-08 11:23:35,616 [ 10532] FINE - #c.i.c.CSharpierLogger - You must install or update .NET to run this application.
App: C:\Users\Park8\AppData\Local\CSharpier\0.18.0\dotnet-csharpier.exe
Architecture: x64
Framework: 'Microsoft.NETCore.App', version '6.0.0' (x64)
.NET location: C:\Program Files\dotnet\
The following frameworks were found:
7.0.5 at [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Learn about framework resolution:
https://aka.ms/dotnet/app-launch-failed
To install missing framework, download:
https://aka.ms/dotnet-core-applaunch?framework=Microsoft.NETCore.App&framework_version=6.0.0&arch=x64&rid=win10-x64
I confirmed that installing the .NET 6 runtime from https://dotnet.microsoft.com/en-us/download/dotnet/6.0 resolved my issue. I will resolve the ticket if you don't think there is a way to have Rider automatically install the correct dependencies when installing the csharpier plugin. With .NET version 7 available now, I just hadn't needed to install the previous version until this plugin so it wasnt installed.
I'm not sure if I can get Rider to install dotnet, but I can at least modify the plugin to handle this and display an error letting the user what is happening. I'll use this issue to keep track of doing that.
If you update to the latest version of CSharpier, it does target net6 or net7 so you'd no longer need net6 installed.
In case this may help anyone . I had very similar issues - CSharpier Rider plugin could not format files and I had errors similar to the ones described above.
In my case issue was caused by a non-standard .NET install location.
I prefer to install .NET using dotnet-install script, and have it installed into /opt/dotnet, with /opt/dotnet/dotnet tool symlinked to /usr/local/bin/dotnet for convenience.
Most of the things work just fine - building from commandline, Rider, VSCode all good with this setup. But there seems to be something wrong with the dotnet tools. I could run csharpier from command line via dotnet tool run:
$ dotnet tool run dotnet-csharpier -- .
Total time: 328ms
Total files: 733
but I could not run dotnet-scharpier from .dotnet/tools:
$ which dotnet-csharpier
/home/iblazhko/.dotnet/tools/dotnet-csharpier
$ dotnet-csharpier .
You must install .NET to run this application.
App: /home/iblazhko/.dotnet/tools/dotnet-csharpier
Architecture: x64
App host version: 7.0.5
.NET location: Not found
$ dotnet --info
.NET SDK (reflecting any global.json):
Version: 6.0.408
Commit: 0c3669d367
Runtime Environment:
OS Name: pop
OS Version: 22.04
OS Platform: Linux
RID: linux-x64
Base Path: /opt/dotnet/sdk/6.0.408/
Host:
Version: 7.0.5
Architecture: x64
Commit: 8042d61b17
.NET SDKs installed:
6.0.408 [/opt/dotnet/sdk]
7.0.302 [/opt/dotnet/sdk]
.NET runtimes installed:
Microsoft.AspNetCore.App 6.0.16 [/opt/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 7.0.5 [/opt/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.NETCore.App 6.0.16 [/opt/dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 7.0.5 [/opt/dotnet/shared/Microsoft.NETCore.App]
Same problem with other tools, so it is not csharpier-specific.
In my case fix was to specify location of my .NET installation in /etc/dotnet/install_location.
$ sudo mkdir -p /etc/dotnet
$ echo "/opt/dotnet" | sudo tee /etc/dotnet/install_location
/opt/dotnet
After I did that, both dotnet-csharpier and CSharpier Rider plugin work.
Woohoo! Thank you, @iblazhko! In my case (MacOS), I even had to change /etc/dotnet/install_location_arm64. I've been poking around this problem for far too long. Thanks for pointing this out!
The changes to the rider plugin for 1.6.1 in #1190 have better support for dotnet commands and finding the dotnet installation. It will be available in a day or two.