Question: I am creating an RSA pki in Fsharp and trying to load a private key:

```
  let getRsa () =
    let rsa = RSA.Create()
    let privateKey = getPrivateKey()
    let bytesRead = ref 0
    match privateKey with
      | Some priv ->
          rsa.ImportRSAPrivateKey(source = priv, bytesRead = bytesRead)
          Some rsa
      | None -> None

```

Unfortunately this does not fly because:

> 
> This expression was expected to have type
> 'ReadOnlySpan' but here has type
> 'byte []' F# Compiler(1)
> 
> 
> 

Is there a way to convert to ReadOnlySpan?

Answer: 
You can create a `ReadOnlySpan` by passing the byte array into the [relevant constructor](https://learn.microsoft.com/en-us/dotnet/api/system.readonlyspan-1.-ctor?view=netcore-3.1#System_ReadOnlySpan_1__ctor__0___):

```ml
System.ReadOnlySpan(priv)

```
It seems that the following works:

```
let spanToROSpan (span : Span<'a>) : ReadOnlySpan<'a> =
    Span<_>.op_Implicit(span)

```

And later

```
spanToROSpan(priv.AsSpan())

```