-
Notifications
You must be signed in to change notification settings - Fork 86
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SetupDiGetDeviceInterfaceDetail() throws MashalDirectiveException "Pointers cannot reference marshaled structures" #1184
Comments
Thanks for reporting. The |
I tested this and it appeared to work. I think it would be safe. -internal global::Windows.Win32.VariableLengthInlineArray<char> DevicePath;
+internal global::Windows.Win32.VariableLengthInlineArray<char, ushort> DevicePath; and - internal struct VariableLengthInlineArray<T>
+ internal struct VariableLengthInlineArray<T, T2>
where T : unmanaged
+where T2 : unmanaged
{
- internal T e0;
+ internal T2 e0;
internal unsafe ref T this[int index]
{
[UnscopedRef]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
- get => ref Unsafe.Add(ref this.e0, index);
+ get => ref Unsafe.Add(ref Unsafe.AsRef<T>(Unsafe.AsPointer(ref this.e0)), index);
} This works by changing the field from @tannergooding @AaronRobinsonMSFT do you have any ideas here? |
A nit on this statement. The concept of "managed" or "unmanaged" is historically a C# ism and not defined by the runtime. The runtime deals with the terms blittable and non-blittable. In .NET the
Using |
@AaronRobinsonMSFT Do you mean in .NET Framework? .NET 8 didn't throw an exception in the OP's repro -- only .NET Framework did. That seems to suggest that .NET 8 considers |
Hmmm. That is surprising. Are you using |
No. |
I can confirm that it will not throw when the |
Hi, I just ran into this issue. Let me know if any other info would be helpful!
Actual behavior
Calling SetupDiGetDeviceInterfaceDetail() in a net48 project results in:
Expected behavior
It should be callable. It worked in version 0.3.49-beta.
Repro steps
NativeMethods.txt
content:NativeMethods.json
: Not presentAny of your own code that should be shared?
Program.cs:
Context
LangVersion
8.0The text was updated successfully, but these errors were encountered: