dotnet / dotnet/fsharp

Trying to use `NativePtr.toVoidPtr` or `.ToPointer` causes `TypeLoadException`

Open
#9,957 9 comments 1 reaction 0 assignees View on GitHub
Area-Compiler-Checking Area-Compiler-Checking-Byref Feature Request Needs-RFC
Dominant language
F#
Stars
4.3k
Forks
876
Avg merge
4d 11h
Merged PRs (30d)
131

Description

**Repro steps**

Provide the steps required to reproduce the problem:

1. run code below
```fsharp
#nowarn "9"

open FSharp.NativeInterop

[]
let main argv =
let numbers = [| 1..10 |]
use v = fixed numbers
let v' = NativePtr.toVoidPtr v
printfn "void = %A" v'
0
```
[Project to reproduce the problem](https://github.com/dotnet/fsharp/files/5089306/repro.zip)

**Expected behavior**
`toVoidPtr` should just work and convert `nativeptr` to `voidptr`

**Actual behavior**
It throws this when run:
```
Unhandled exception. System.TypeLoadException: The generic type 'Microsoft.FSharp.Core.FSharpFunc`2' was used with an invalid instantiation in assembly 'FSharp.Core, Version=4.7.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.
```

**Related information**
* Operating system: Linux and Windows (I tried both)
* .NET Core 3.1
* Visual Studio Code

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.