-
Notifications
You must be signed in to change notification settings - Fork 4.5k
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
LibraryImport fails to Marshal ByValTStr (SYSLIB1051) #75376
Comments
Tagging subscribers to this area: @dotnet/interop-contrib Issue DetailsDescriptionI just noticed a strange behavior when implementing the Winsock API. Reproduction Steps internal const string Ws2_32 = "ws2_32.dll";
[StructLayout(LayoutKind.Sequential)]
internal struct WSAData
{
public short wVersion;
public short wHighVersion;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 257)]
public string szDescription;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 129)]
public string szSystemStatus;
public short iMaxSockets;
public short iMaxUdpDg;
public int lpVendorInfo;
}
[LibraryImport(Ws2_32, SetLastError = true)]
internal static partial int WSAStartup(in short wVersionRequested, out WSAData lpWSAData); Expected behaviorThat it works. Actual behaviorSYSLIB1051 Regression?No response Known Workarounds
Configuration7.0.100-preview.7.22377.5 Other informationNo response
|
This is a known deficiency in the new system. We do not have a source-generator today for generating marshalling information for a user-defined type. You'll need to manually define a marshaller using the new custom type marshaller model if you want to use a non-blittable user-defined type with LibraryImport. |
@deeprobin This is by design. See our documentation for this here. |
Description
I just noticed a strange behavior when implementing the Winsock API.
Reproduction Steps
Expected behavior
That it works.
Actual behavior
SYSLIB1051
Regression?
No response
Known Workarounds
DllImportAttribute
instead ofLibraryImportAttribute
.Configuration
7.0.100-preview.7.22377.5
Other information
No response
The text was updated successfully, but these errors were encountered: