oleg-shilo / cs-script.npp

CS-Script (C# Intellisense) plugin for Notepad++ (x86/x64)
MIT License
246 stars 52 forks source link

Cannot locate Roslyn compiler Path cannot be null #45

Closed githubjbassett closed 4 years ago

githubjbassett commented 4 years ago

I am using version 1.7.14.0. I have the setting 'C# 7 support (Roslyn) - Requires .NET 4.6' unchecked. When I run a script, I get the Cannot locate Roslyn compiler Path cannot be null exception. I have attempted to fulfill the requirement in every way I can find, but nothing works. I see the CSSRoslynProvider.dll. When I try to upgrade the .NET Framework, it tells me that a newer version is already installed. This is Windows Server 2012 R2 Standard. It isn't the script, because it works on other servers and when you run it from Notepad++. I've seen this before and to fix it I copied the plugins folder from a working machine, but that didn't help this case. I uninstalled and reinstalled the plugin. Any suggestions would be great.

oleg-shilo commented 4 years ago

Before I we try fix the problem I wold like to get a bit more information.

It isn't the script, because it works on other servers and when you run it from Notepad++.

Does this mean that C#7 scripts are working when they are executed from Notepad++?

githubjbassett commented 4 years ago

I don't think so. In attempting to answer this question, I created a script and added the css_args -provider and pointed it to the CSSRoslynProvider.dll and I get the same error. So, probably not. The issue is that I don't need any C#7 functionality and was trying to run cs_script using the default compiler. Unfortunately, that isn't working for me. For whatever reason, running it from command line is different from running it in notepad++. I created a new script (hello world) and it runs fine in Notepad++, but from command line produces this exception:

Error: Specified file could not be compiled.

System.Exception: Cannot locate Roslyn compiler. ---> System.ArgumentNullExcepti on: Path cannot be null. Parameter name: path at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolean useLongPath, Boolean checkHost) at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share) at System.IO.File.OpenRead(String path) at Microsoft.CodeDom.Providers.DotNetCompilerPlatform.Compiler.get_CompilerName() --- End of inner exception stack trace --- at Microsoft.CodeDom.Providers.DotNetCompilerPlatform.Compiler.get_CompilerName() at Microsoft.CodeDom.Providers.DotNetCompilerPlatform.Compiler.FromFileBatch(CompilerParameters options, String[] fileNames) at Microsoft.CodeDom.Providers.DotNetCompilerPlatform.Compiler.CompileAssemblyFromFileBatch(CompilerParameters options, String[] fileNames) at csscript.CSExecutor.CompileAssembly(ICodeCompiler compiler, CompilerParameters compilerParams, String[] filesToCompile) at csscript.CSExecutor.Compile(String scriptFileName) at csscript.CSExecutor.ExecuteImpl()

githubjbassett commented 4 years ago

In troubleshooting this, I set the useAlternativeComplier to CodeDOM. Now, I get a message that says: Cannot find alternative compiler (CodeDOM). Loading default compiler instead.

And then it works the way I expect. Then, I changed the hideCompilerWarnings to True and it works like I want.

oleg-shilo commented 4 years ago

It seems like a problem with the .NET deployment on your system.

CS-Script engine always tries to locate a stock alternative compiler (CSSRoslynProvider.dll) in the engine directory (where cscs.exe is) thus if it finds it loads it. This works on your box as expected. Then CSSRoslynProvider tries to local Roslyn compiler csc.exe in the standard .NET deployment locations (e.g. program_files). This step fails on your system. I do not know why.

Notepad++ comes with its own copy of cs-script and CSSRoslynProvider, which is disabled by default if I am not mistaken. BTW you can always suppress alternative provider by passing -pvdr:none as a command line arg or via //css_args. And if you want to disable it permanently you may just delete CSSRoslynProvider.dll.

Though if for whatever reason Roslyn's csc.exe exists but not in the expected (by cs-script) location you can always provide its location manually:

This might be that little help that CSSRoslynProvider just needs.

githubjbassett commented 4 years ago

That helps me, thank you for taking the time to explain it.