oleg-shilo / cs-script

C# scripting platform
http://www.cs-script.net
MIT License
1.62k stars 235 forks source link

System.ArgumentNullException: Value cannot be null. (Parameter 'path') on macOS Monterey #286

Closed mwwoda closed 2 years ago

mwwoda commented 2 years ago

Hello, I'm not sure if cs-script is officialy supported on macOS, but I wanted to push my luck and I installed it via vs code as an extension. When trying to call CS-Script: About command I get the following error

CS-Script.VSCode - v2.0.1
-------------------------------------------------------
System.ArgumentNullException: Value cannot be null. (Parameter 'path')
   at System.IO.Directory.CreateDirectory(String path)
   at CSScripting.PathExtensions.EnsureDir(String path, Boolean rethrow)
   at cscs.Program.Main(String[] args)
-------------------------------------------------------
Syntaxer
   /Users/mwoda/Library/Application Support/Code/User/cs-script.user/dotnet/syntaxer/syntaxer.dll
Extension
   /Users/mwoda/.vscode/extensions/oleg-shilo.cs-script-2.0.1/out

A quick glance at the code and it looks like there is a problem with Runtime.CustomCommandsDir.EnsureDir(); line in cscs/Program.cs. It tries to create a directory under CommonApplicationData which translates to /usr/share path under macOS. This directory is protected by SIP, so I tried to disable that with csrutil disable. I still get the error when trying to manually create the cs-scriptdirectory.

mkdir: cs-script: Read-only file system

It seems that since Catalina version it is not possible to store data in read-only system volume https://support.apple.com/en-gb/HT210650

Would it be possible to make CustomCommandsDir and other directories associated with CommonApplicationData more configurable? Or move them to a different location?

OS Version: macOS Monterey 12.2.1

oleg-shilo commented 2 years ago

Yes, it would. And... without your report, it's impossible to know what the problems with a specific OS, so thank you.

It is a strange problem as CommonApplicationData means "any app can write here". Apparently, the OS developers decided that it should not be the case :(

Marking the issue as an enhancement to release the customization that would allow specifying the arbitrary root for the app data.

As for macOS support, ccs-script can be run on any OS supporting .NET 5+. But I can only test it on Linux (https://github.com/oleg-shilo/cs-script/wiki/CS-Script-on-Linux) and Win.

oleg-shilo commented 2 years ago

Can you please try this pre-release: https://github.com/oleg-shilo/cs-script/releases/tag/v4.4.2

I found that the only use-case when cs-script is using CommonApplicationData based folders is to import the scripts. Meaning that ignoring the exception on EnsureDir may be enough to address the problem. If not I will create a more comprehensive solution.

Let me know how did it go for you.

mwwoda commented 2 years ago

I just ran a small .cs file with simple printing and it worked!

oleg-shilo commented 2 years ago

Perfect. Then I will rerelease tmr as a full release. Thank you. Testing on Mac was always a difficult part for me

oleg-shilo commented 2 years ago

Done the build that you have tested is now fully released and published on choco