I've searched around for this but nobody seems to be having quite the same issue with F# .fsx scripts not finding namespaces. I've got Common project that builds fine and is picked up by intellisense in another project but the script in that same project proclaims it as not defined even though hovering over the #r "Common.dll" finds the full path. The common code:
namespace Common
open System
open System.Text
open System.Security.Cryptography
module Guid =
let swapBytes (a: byte[]) =
Array.concat [ Array.rev a.[..3] ; Array.rev a.[4..5] ; Array.rev a.[6..7]; a.[8..15] ]
// Implementaion of http://www.ietf.org/rfc/rfc4122.txt section 4.3 version 5 (Name Based using SHA-1)
// Based on C# at https://github.com/LogosBible/Logos.Utility/blob/master/src/Logos.Utility/GuidUtility.cs
type System.Guid with
static member FromName (guid:System.Guid) (name:string) =
let nameBytes: byte[] = Encoding.UTF8.GetBytes name
let nameSpaceBytes = guid.ToByteArray() |> swapBytes
use algorithm = SHA1.Create()
algorithm.TransformBlock (nameSpaceBytes, 0, nameSpaceBytes.Length, null, 0) |> ignore
algorithm.TransformFinalBlock(nameBytes, 0, nameBytes.Length) |> ignore
let hash = algorithm.Hash;
let newGuid = Array.create 16 0uy
Array.Copy(hash, 0, newGuid, 0, 16)
Array.set newGuid 6 ((newGuid.[6] &&& 0x0Fuy) ||| (5uy <<< 4))
Array.set newGuid 8 ((newGuid.[8] &&& 0x3Fuy) ||| 0x80uy)
newGuid |> swapBytes |> System.Guid
The .fsx content:
#I @"..\Common\bin\Debug"
#r "Common.dll"
open Common
let NamedGuid = System.Guid.FromName (Guid("190bbe82-5692-43a4-b825-079f41fc55c0"))
This is in VS2015. What is missing?
You need to open the Guid
module as well, or annotate it with the [<AutoOpen>]
attribute. This will resolve the reference to System.Guid.FromName
.
And after you do that, you will also need to open the System
namespace in order to access the Guid
constructor (or call System.Guid
directly).
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.