Implementing a generic interface that contains a member returning nativeptr<'T> leads to a TypeLoadException with message
Signature of the body and declaration in a method implementation do not match.
when using that type. Curiously, implementing the interface in a generic type works as expected. I'm not sure if I'm doing something completely unreasonable here, but I'd expect a compiler error at least.
This does not seem to be related to .NET 7.
Repro steps
ConsoleApp1.zip
type IFoo<'T when 'T : unmanaged> =
abstract member Pointer : nativeptr<'T>
type Broken() =
member x.Pointer : nativeptr<int> = Unchecked.defaultof<_>
interface IFoo<int> with
member x.Pointer = x.Pointer
type Working<'T when 'T : unmanaged>() =
member x.Pointer : nativeptr<'T> = Unchecked.defaultof<_>
interface IFoo<'T> with
member x.Pointer = x.Pointer
[<EntryPoint>]
let main argv =
// Works
let a = Working<int>()
// Throws System.TypeLoadException: 'Signature of the body and declaration in a method implementation do not match.
let b = Broken()
0
Expected behavior
Should run or produce a compile-time error if not valid.
Actual behavior
Throws an TypeLoadException at runtime.
Related information
- Windows 10
- .NET 6 (and 7 tested on a colleagues machine)
Implementing a generic interface that contains a member returning
nativeptr<'T>leads to aTypeLoadExceptionwith messagewhen using that type. Curiously, implementing the interface in a generic type works as expected. I'm not sure if I'm doing something completely unreasonable here, but I'd expect a compiler error at least.
This does not seem to be related to .NET 7.
Repro steps
ConsoleApp1.zip
Expected behavior
Should run or produce a compile-time error if not valid.
Actual behavior
Throws an
TypeLoadExceptionat runtime.Related information