Skip to content

MissingFieldException when assigning to a function pointer field #12551

@kostya9

Description

@kostya9

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 package
<ItemGroup>
  <PackageReference Include="TerraFX.Interop.Windows" Version="10.0.20348" />
</ItemGroup>
  1. Use the following code:
open TerraFX.Interop.Windows

let mutable windowClassDescriptor = WNDCLASSEXW()
windowClassDescriptor.lpfnWndProc <- 0n // lpfnWndProc is of type delegate* unmanaged<HWND, uint, WPARAM, LPARAM, LRESULT> in C#

printfn "Successfully Finished" 

Zip with repro:
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 <StartupCode$MissingFieldExceptionRepro>.$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. Commenting out the assignment fixes the problem, but the field is required.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Area-Compiler-CheckingType checking, attributes and all aspects of logic checkingArea-Compiler-Checking-Byrefbyref, inref, outref, byref-like types, NativePtr, function pointers, struct semanticsBugImpact-Low(Internal MS Team use only) Describes an issue with limited impact on existing code.

    Type

    Projects

    Status

    New

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions