Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can not run scripts after installing VS2022 #258

Closed
caesay opened this issue Oct 29, 2021 · 4 comments
Closed

Can not run scripts after installing VS2022 #258

caesay opened this issue Oct 29, 2021 · 4 comments

Comments

@caesay
Copy link

caesay commented Oct 29, 2021

VS2022 installs the dotnet6 sdk, and this has caused cs-script to fail to execute all scripts, of any kind. I can't see any command line arguments that might be helpful.

C:\Users\Caelan>cscs "C:\Tools\scripts\\locking.cs"
Error: Specified file could not be executed.

Could not load type 'System.Runtime.CompilerServices.DefaultInterpolatedStringHandler' from assembly 'System.Runtime, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.

Presumably related to some of the changes mentioned here https://devblogs.microsoft.com/dotnet/string-interpolation-in-c-10-and-net-6/

Is there a way to instruct cs-script to use the dotnet 5 runtime that I'm unaware of?

@oleg-shilo
Copy link
Owner

Hi Caelan, sorry for the delay. It was a 4-days weekend in Mel :)

That is an interesting problem. cscs is compiled for .NET five and I expect it to run compilers for .NET 6, not .NET 6.

Can you please check if forcing it to compile against .NET 5 Roslyn would do the trick:

cscs -ng:roslyn "C:\Tools\scripts\locking.cs"

@caesay
Copy link
Author

caesay commented Nov 3, 2021

Hi Oleg, thanks for the response.

cscs was working fine before I installed VS2022 / net6 SDK. I have tried with your suggestion and the result is the same, I've also tried with all kinds of scripts, even a simple Console.WriteLine causes the issue when SDK6 is installed.

C:\Users\Caelan>cscs -ng:roslyn "C:\Tools\scripts\locking.cs"
Error: Specified file could not be executed.

Could not load type 'System.Runtime.CompilerServices.DefaultInterpolatedStringHandler' from assembly 'System.Runtime, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.

For reference, this is the list of runtimes I have installed

>dotnet --info

NET SDK (reflecting any global.json):
 Version:   6.0.100-rc.2.21505.57
 Commit:    ab39070116

Runtime Environment:
 OS Name:     Windows
 OS Version:  10.0.19042
 OS Platform: Windows
 RID:         win10-x64
 Base Path:   C:\Program Files\dotnet\sdk\6.0.100-rc.2.21505.57\

Host (useful for support):
  Version: 6.0.0-rc.2.21480.5
  Commit:  6b11d64e7e

.NET SDKs installed:
  5.0.301 [C:\Program Files\dotnet\sdk]
  5.0.401 [C:\Program Files\dotnet\sdk]
  6.0.100-rc.2.21505.57 [C:\Program Files\dotnet\sdk]

.NET runtimes installed:
  Microsoft.AspNetCore.All 2.1.28 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.App 2.1.28 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 3.1.16 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 5.0.7 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 5.0.10 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 5.0.11 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 6.0.0-rc.2.21480.10 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 2.1.28 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 3.1.11 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 3.1.16 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 5.0.7 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 5.0.10 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 5.0.11 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 6.0.0-rc.2.21480.5 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.WindowsDesktop.App 3.1.11 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 3.1.16 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 5.0.7 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 5.0.10 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 5.0.11 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 6.0.0-rc.2.21501.6 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

@oleg-shilo
Copy link
Owner

oleg-shilo commented Nov 4, 2021

Found the problem when installed .NET 6 SDK. Though not entirely sure that it is absolutely the same as in your environment.
The cause is the deployment model .NET is relying on.

While all SDKs installed are fully independent (e.g. their compilers csc.exe), the launch dotnet.exe is patched after the SDK installation with the version specific to the last SDK installed. Meaning that a simple dotnet csc.dll call will fail if the csc is a .NET 5 (x86) assembly and dotnet is a .NET6 (x64) executable. Like in my case.

In your case, you may have both SDKs of the same architecture but still, they may not be compatible type wise.

I will prepare a hotfix release so you can test the build with the deterministic probing of both csc and dotnet. This may fix the problem.

But... if it does not then please send me your exact script as in my environment .NET 6 SDK breaks the execution but with the CPU architecture incompatibility. And Roslyn engine does fix the problem. Meaning that there are differences in between our tests either in our environments or our scripts.

Stay tuned

oleg-shilo pushed a commit that referenced this issue Nov 4, 2021
- Updated `-speed` and `-code` with the complete support `-ng:*` switches
- Added `IEvaluator.IsCachingEnabled`. Ite as always available from the conctrete types implementing `IEvaluator` and now it is moved directly to the interface.
- Added `-servers:start` and `-servers:stop` command to control both Roslyn and csc build servers at the same time
- CSScriptLib: Native API `CacheEnabled` marked as obsolete
- Issue #258: Can not run scripts after installing VS2022
- Issue #257: Ability to catch AppDomain.UnhandledException in a not-hosted script (cscs)
- Issue #255: Relative path for cscs.exe -out option results in wrong output folder
- Issue #254: Script merger for hosted scripts
- Issue #253: Supports both .Net Framework and .Net 5
- Issue #252: System.NullReferenceException: Object reference not set to an instance of an object. (updated API doc)
- Added auto-generation of the CLI MD documentation with `-help cli:md`. To be used to generate GitHub wiki page during the build
- Fixed Debian packaging problem (`/n/r` needed replacement with `\n`)
@oleg-shilo
Copy link
Owner

oleg-shilo added a commit that referenced this issue Nov 14, 2021
### Misc

- Added auto-generation of the CLI MD documentation with -help cli:md. To be used to generate GitHub wiki page during the build
- Fixed Debian packaging problem (/n/r needed replacement with \n)
- Issue #253: Supports both .Net Framework and .Net 5

### CLI

- Updated -speed and -code with the complete support -ng:* switches
- Added -servers:start and -servers:stop command to control both Roslyn and csc build servers at the same time
- Issue #258: Can not run scripts after installing VS2022
- Issue #257: Ability to catch AppDomain.UnhandledException in a not-hosted script (cscs)
- Issue #255: Relative path for cscs.exe -out option results in wrong output folder
- Issue #254: Script merger for hosted scripts
- Issue #252: System.NullReferenceException: Object reference not set to an instance of an object. (updated API doc)

### CSScriptLib

- Native API CacheEnabled marked as obsolete
- Added IEvaluator.IsCachingEnabled. It is always available from the concrete types implementing IEvaluator and now it is moved directly to the interface.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants