Skip to content

Provide custom marshaller for USER_INFO_1 #81705

@AaronRobinsonMSFT

Description

@AaronRobinsonMSFT

In PR #81480, the following P/Invoke was failing to compile when targeting .NET 8.

[LibraryImport("netapi32.dll", SetLastError = true)]
internal static partial uint NetUserAdd([MarshalAs(UnmanagedType.LPWStr)] string servername, uint level, ref USER_INFO_1 buf, out uint parm_err);

The failure is because in the current dotnet/runtime official build this P/Invoke is only compiled to target .NET 6 and so the LibraryImport source generated degrades to a DllImport. We should provide a custom marshaller for the struct below

[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
internal struct USER_INFO_1
{
public string usri1_name;
public string usri1_password;
public uint usri1_password_age;
public uint usri1_priv;
public string usri1_home_dir;
public string usri1_comment;
public uint usri1_flags;
public string usri1_script_path;
}

This scenario could be made to "just work" with the following issue addressed: #81656

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions