dotnet / roslyn

The Roslyn .NET compiler provides C# and Visual Basic languages with rich code analysis APIs.
https://docs.microsoft.com/dotnet/csharp/roslyn-sdk/
MIT License
19.01k stars 4.03k forks source link

Scripts breaking after upgrade to .NET 7 due to missing classes from System.Security.Cryptography #66249

Open brandedoutcast opened 1 year ago

brandedoutcast commented 1 year ago

Describe the bug

Both fsharp & csharp scripts fail to see any class from System.Security.Cryptography on .NET 7

To Reproduce

Running this code in an fsx file results in error FS0039: The value, namespace, type or module 'HMACSHA1' is not defined. Maybe you want one of the following: hash

open System.Text
open System.Security.Cryptography

let key = Encoding.Default.GetBytes("key")
let source = Encoding.Default.GetBytes("source")
HMACSHA1.HashData(key, source) |> printfn "hash %A"

A C# version of this code in a .csx file results in 'HMACSHA1' does not contain a definition for 'HashData'

Exceptions (if any)

error FS0039: The value, namespace, type or module 'HMACSHA1' is not defined. Maybe you want one of the following: hash

Further technical details

Runtime Environment: OS Name: Windows OS Version: 10.0.22621 OS Platform: Windows RID: win10-x64 Base Path: C:\Program Files\dotnet\sdk\7.0.100\

Host: Version: 7.0.0 Architecture: x64 Commit: d099f075e4

.NET SDKs installed: 6.0.202 [C:\Program Files\dotnet\sdk] 6.0.400 [C:\Program Files\dotnet\sdk] 7.0.100 [C:\Program Files\dotnet\sdk]

.NET runtimes installed: Microsoft.AspNetCore.App 5.0.17 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 6.0.10 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 6.0.11 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 7.0.0 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.NETCore.App 3.1.24 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 3.1.30 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 5.0.17 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 6.0.4 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 6.0.10 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 6.0.11 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 7.0.0 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.WindowsDesktop.App 3.1.24 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 5.0.17 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 6.0.4 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 6.0.10 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 6.0.11 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 7.0.0 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

Other architectures found: x86 [C:\Program Files (x86)\dotnet] registered at [HKLM\SOFTWARE\dotnet\Setup\InstalledVersions\x86\InstallLocation]

Environment variables: Not set

global.json file: Not found

Learn more: https://aka.ms/dotnet/info

Download .NET: https://aka.ms/dotnet/download

dotnet-issue-labeler[bot] commented 1 year ago

I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label.

marcpopMSFT commented 1 year ago

@KevinRansom I don't appear to have permissions to transfer this to the fsharp repo. Can you take a look and see if you can?

nagilson commented 1 year ago

Deleted that comment as its copied in the F# one. But this is specifically talking about C#, the other issue is just F#.

marcpopMSFT commented 1 year ago

Moving this one over to roslyn. Could go to csharp interactive. There's a separate issue tracking the Fsharp behavior.

DunetsNM commented 1 year ago

I had the same bug for MD5 in my fsx script , side stepped the problem by importing arbitrary wrapper nuget over the original MD5 implemenation:

#r "nuget: CryptHash.Net, 3.6.1"