question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

FSI netcore not seeing System.Security.Cryptography asm

See original GitHub issue

In VS Version 17.4.0 Preview 2.1 editing a fsx file with “Use .NET Core Scripting” enabled:

image

Not showing any types from System.Security.Cryptography asm, (Aes, AesCcm, AesCng, …)

In FSI (F# Interactive version 12.0.5.0 for F# 7.0):

$ dotnet fsi

Microsoft (R) F# Interactive version 12.0.5.0 for F# 7.0
Copyright (c) Microsoft Corporation. All Rights Reserved.

For help type #help;;

> System.Security.Cryptography.MD5.Create();;

  System.Security.Cryptography.MD5.Create();;
  -----------------------------^^^

stdin(12,30): error FS0039: The value, constructor, namespace or type 'MD5' is not defined.

Yet reflection works fine:

 > type ComputeHash = delegate of byte[] -> byte[]
let computeHash  =
    let asm = System.AppDomain.CurrentDomain.GetAssemblies() |> Seq.find (fun x -> x.FullName.StartsWith("System.Security.Cryptography,"))
    let md5 = asm.GetTypes() |> Seq.find (fun x -> x.Name = "MD5")
    let computeHashMeth = md5.GetMethod("ComputeHash", [| typeof<byte[]> |])
    let md5obj = md5.GetMethod("Create",[||]).Invoke(null,[||])
    let d : ComputeHash = computeHashMeth.CreateDelegate(md5obj)
    fun x -> d.Invoke x
;;
type ComputeHash =
  delegate of byte[] -> byte[]
val computeHash: (byte[] -> byte[])

> computeHash [|0uy|];;
val it: byte[] =
  [|147uy; 184uy; 133uy; 173uy; 254uy; 13uy; 160uy; 137uy; 205uy; 246uy; 52uy;
    144uy; 79uy; 213uy; 159uy; 113uy|]

A F# net7.0 project works fine image

Compiles and runs.

FSI without “Use .NET Core Scripting” works fine.

Issue Analytics

  • State:closed
  • Created a year ago
  • Reactions:5
  • Comments:7

github_iconTop GitHub Comments

7reactions
knt141commented, Nov 30, 2022

work around: #r "System.Security.Cryptography" in top of fsx

1reaction
ThisFunctionalTomcommented, Nov 10, 2022

We have the same problem.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Scripts breaking after upgrade to .NET 7 due to missing ...
Describe the bug Both fsharp & csharp scripts fail to see any class from System.Security.Cryptography on .NET 7 To Reproduce Running this ...
Read more >
Announcing F# 7 - .NET Blog
The F# compiler is improved to offer reference assemblies, trimmability, better code gen, ARM64 support, performance enhancements and bug fixes.
Read more >
c# - Could not load file or assembly 'System.Security. ...
So your library references System.Security.Cryptography.Algorithms 4.3.0 however the actual version of the assembly to load for your ...
Read more >
Untitled
Cryptography Namespace Microsoft Learn Web5 thg 10, 2022 · FSI netcore not seeing System.Security.Cryptography asm · Issue #14024 · dotnet/fsharp · GitHub.
Read more >
Implementing Web Services Security - MyF5
To use web services security for encryption, decryption, and digital signature signing and verification, you must upload client and server certificates onto ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found