dotnet / dotnet/fsharp

MissingFieldException when assigning to a function pointer field

Open
#12,551 0 comments 0 reactions 0 assignees View on GitHub
Area-Compiler-Checking Area-Compiler-Checking-Byref Bug Impact-Low
Dominant language
F#
Stars
4.3k
Forks
876
Avg merge
4d 11h
Merged PRs (30d)
131

Description

Trying to use a field with function pointer type throws a MissingFieldException in runtime.

**Repro steps**

Provide the steps required to reproduce the problem:

1. Create a new F# console app
2. Add [TerraFx.Interop.Windows](https://github.com/terrafx/terrafx.interop.windows) package
```xml

```
2. Use the following code:
```fsharp
open TerraFX.Interop.Windows

let mutable windowClassDescriptor = WNDCLASSEXW()
windowClassDescriptor.lpfnWndProc <- 0n // lpfnWndProc is of type delegate* unmanaged in C#

printfn "Successfully Finished"
```

Zip with repro:
[MissingFieldExceptionRepro.zip](https://github.com/dotnet/fsharp/files/7786336/MissingFieldExceptionRepro.zip)

**Expected behavior**

Program finishes and prints "Successfully Finished"

**Actual behavior**

Throws exception
```
Unhandled exception. System.MissingFieldException: Field not found: 'TerraFX.Int
erop.Windows.WNDCLASSEXW.lpfnWndProc'.
at .$Program.main@()

```

**Known workarounds**

No workarounds known to me

**Related information**

Provide any related information (optional):

* Operating system: Win11
* .NET Runtime kind (.NET Core, .NET Framework, Mono): .NET 6, SDK 6.0.100
* Editing Tools (e.g. Visual Studio Version, Visual Studio): Rider (and command line)

[Here is the definition of the field in the TerraFX repo](https://github.com/terrafx/terrafx.interop.windows/blob/main/sources/Interop/Windows/Windows/um/WinUser/WNDCLASSEXW.cs#L19). Commenting out the assignment fixes the problem, but the field is required.

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.