Skip to content
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

Closed
deeprobin opened this issue Sep 9, 2022 · 3 comments
Closed

LibraryImport fails to Marshal ByValTStr (SYSLIB1051) #75376

deeprobin opened this issue Sep 9, 2022 · 3 comments

Comments

@deeprobin
Copy link
Contributor

Description

I 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 behavior

That it works.

Actual behavior

SYSLIB1051

Regression?

No response

Known Workarounds

  • Usage of DllImportAttribute instead of LibraryImportAttribute.

Configuration

7.0.100-preview.7.22377.5

Other information

No response

@ghost ghost added the untriaged New issue has not been triaged by the area owner label Sep 9, 2022
@ghost
Copy link

ghost commented Sep 9, 2022

Tagging subscribers to this area: @dotnet/interop-contrib
See info in area-owners.md if you want to be subscribed.

Issue Details

Description

I 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 behavior

That it works.

Actual behavior

SYSLIB1051

Regression?

No response

Known Workarounds

  • Usage of DllImportAttribute instead of LibraryImportAttribute.

Configuration

7.0.100-preview.7.22377.5

Other information

No response

Author: deeprobin
Assignees: -
Labels:

area-System.Runtime.InteropServices

Milestone: -

@jkoritzinsky
Copy link
Member

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.

@AaronRobinsonMSFT
Copy link
Member

@deeprobin This is by design. See our documentation for this here.

@ghost ghost removed the untriaged New issue has not been triaged by the area owner label Sep 11, 2022
@ghost ghost locked as resolved and limited conversation to collaborators Oct 11, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants