diff --git a/src/System.Management.Automation/engine/Interop/Windows/CreateHardLink.cs b/src/System.Management.Automation/engine/Interop/Windows/CreateHardLink.cs index a6cbc61619e..f27f095fc1a 100644 --- a/src/System.Management.Automation/engine/Interop/Windows/CreateHardLink.cs +++ b/src/System.Management.Automation/engine/Interop/Windows/CreateHardLink.cs @@ -9,7 +9,7 @@ internal static partial class Interop { internal static unsafe partial class Windows { - [LibraryImport("api-ms-win-core-file-l2-1-0.dll", EntryPoint = "CreateHardLinkW", StringMarshalling = StringMarshalling.Utf16)] + [LibraryImport("api-ms-win-core-file-l2-1-0.dll", EntryPoint = "CreateHardLinkW", StringMarshalling = StringMarshalling.Utf16, SetLastError = true)] [return: MarshalAs(UnmanagedType.Bool)] internal static partial bool CreateHardLink(string name, string existingFileName, nint securityAttributes); } diff --git a/src/System.Management.Automation/engine/Interop/Windows/CreateSymbolicLink.cs b/src/System.Management.Automation/engine/Interop/Windows/CreateSymbolicLink.cs index 2c4995d8786..c6519f94ec4 100644 --- a/src/System.Management.Automation/engine/Interop/Windows/CreateSymbolicLink.cs +++ b/src/System.Management.Automation/engine/Interop/Windows/CreateSymbolicLink.cs @@ -18,7 +18,7 @@ internal enum SymbolicLinkFlags AllowUnprivilegedCreate = 2, } - [LibraryImport("api-ms-win-core-file-l2-1-0.dll", EntryPoint = "CreateSymbolicLinkW", StringMarshalling = StringMarshalling.Utf16)] + [LibraryImport("api-ms-win-core-file-l2-1-0.dll", EntryPoint = "CreateSymbolicLinkW", StringMarshalling = StringMarshalling.Utf16, SetLastError = true)] [return: MarshalAs(UnmanagedType.I1)] internal static partial bool CreateSymbolicLink(string name, string destination, SymbolicLinkFlags symbolicLinkFlags); }