diff --git a/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleControl.cs b/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleControl.cs
index 7670731fc16..3b78674d89b 100644
--- a/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleControl.cs
+++ b/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleControl.cs
@@ -2818,40 +2818,6 @@ internal static bool IsCJKOutputCodePage(out uint codePage)
#region Cursor
- ///
- /// Wraps Win32 SetConsoleCursorPosition.
- ///
- ///
- /// handle for the console where cursor position is set
- ///
- ///
- /// location to which the cursor will be set
- ///
- ///
- /// If Win32's SetConsoleCursorPosition fails
- ///
- internal static void SetConsoleCursorPosition(ConsoleHandle consoleHandle, Coordinates cursorPosition)
- {
- Dbg.Assert(!consoleHandle.IsInvalid, "ConsoleHandle is not valid");
- Dbg.Assert(!consoleHandle.IsClosed, "ConsoleHandle is closed");
-
- ConsoleControl.COORD c;
-
- c.X = (short)cursorPosition.X;
- c.Y = (short)cursorPosition.Y;
-
- bool result = NativeMethods.SetConsoleCursorPosition(consoleHandle.DangerousGetHandle(), c);
-
- if (!result)
- {
- int err = Marshal.GetLastWin32Error();
-
- HostException e = CreateHostException(err, "SetConsoleCursorPosition",
- ErrorCategory.ResourceUnavailable, ConsoleControlStrings.SetConsoleCursorPositionExceptionTemplate);
- throw e;
- }
- }
-
///
/// Wraps Win32 GetConsoleCursorInfo.
///
@@ -3159,10 +3125,6 @@ out DWORD numberOfEventsRead
[return: MarshalAs(UnmanagedType.Bool)]
internal static extern bool SetConsoleCtrlHandler(BreakHandler handlerRoutine, bool add);
- [DllImport(PinvokeDllNames.SetConsoleCursorPositionDllName, SetLastError = true, CharSet = CharSet.Unicode)]
- [return: MarshalAs(UnmanagedType.Bool)]
- internal static extern bool SetConsoleCursorPosition(NakedWin32Handle consoleOutput, COORD cursorPosition);
-
[DllImport(PinvokeDllNames.SetConsoleModeDllName, SetLastError = true, CharSet = CharSet.Unicode)]
[return: MarshalAs(UnmanagedType.Bool)]
internal static extern bool SetConsoleMode(NakedWin32Handle consoleHandle, DWORD mode);
diff --git a/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHostRawUserInterface.cs b/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHostRawUserInterface.cs
index 2a6ea89176d..bca63be834b 100644
--- a/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHostRawUserInterface.cs
+++ b/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHostRawUserInterface.cs
@@ -190,14 +190,15 @@ public override
set
{
- // cursor position can't be outside the buffer area
-
- ConsoleControl.CONSOLE_SCREEN_BUFFER_INFO bufferInfo;
-
- ConsoleHandle handle = GetBufferInfo(out bufferInfo);
-
- CheckCoordinateWithinBuffer(ref value, ref bufferInfo, "value");
- ConsoleControl.SetConsoleCursorPosition(handle, value);
+ try
+ {
+ Console.SetCursorPosition(value.X, value.Y);
+ }
+ catch (ArgumentOutOfRangeException)
+ {
+ // if screen buffer has changed, we cannot set it anywhere reasonable as the screen buffer
+ // might change again, so we ignore this
+ }
}
}
diff --git a/src/System.Management.Automation/utils/PInvokeDllNames.cs b/src/System.Management.Automation/utils/PInvokeDllNames.cs
index 7dd28be8cdd..bff2ca2656e 100644
--- a/src/System.Management.Automation/utils/PInvokeDllNames.cs
+++ b/src/System.Management.Automation/utils/PInvokeDllNames.cs
@@ -116,27 +116,26 @@ internal static class PinvokeDllNames
internal const string PeekConsoleInputDllName = "api-ms-win-core-console-l2-1-0.dll"; /*103*/
internal const string GetNumberOfConsoleInputEventsDllName = "api-ms-win-core-console-l1-1-0.dll"; /*104*/
internal const string SetConsoleCtrlHandlerDllName = "api-ms-win-core-console-l1-1-0.dll"; /*105*/
- internal const string SetConsoleCursorPositionDllName = "api-ms-win-core-console-l2-1-0.dll"; /*106*/
- internal const string SetConsoleModeDllName = "api-ms-win-core-console-l1-1-0.dll"; /*107*/
- internal const string SetConsoleScreenBufferSizeDllName = "api-ms-win-core-console-l2-1-0.dll"; /*108*/
- internal const string SetConsoleTextAttributeDllName = "api-ms-win-core-console-l2-1-0.dll"; /*109*/
- internal const string SetConsoleWindowInfoDllName = "api-ms-win-core-console-l2-1-0.dll"; /*110*/
- internal const string WriteConsoleOutputDllName = "api-ms-win-core-console-l2-1-0.dll"; /*111*/
- internal const string ReadConsoleOutputDllName = "api-ms-win-core-console-l2-1-0.dll"; /*112*/
- internal const string ScrollConsoleScreenBufferDllName = "api-ms-win-core-console-l2-1-0.dll"; /*113*/
- internal const string SendInputDllName = "ext-ms-win-ntuser-keyboard-l1-2-1.dll"; /*114*/
- internal const string GetConsoleCursorInfoDllName = "api-ms-win-core-console-l2-1-0.dll"; /*115*/
- internal const string SetConsoleCursorInfoDllName = "api-ms-win-core-console-l2-1-0.dll"; /*116*/
- internal const string ReadConsoleInputDllName = "api-ms-win-core-console-l1-1-0.dll"; /*117*/
- internal const string GetVersionExDllName = "api-ms-win-core-sysinfo-l1-1-0.dll"; /*118*/
- internal const string FormatMessageDllName = "api-ms-win-core-localization-l1-2-0.dll"; /*119*/
- internal const string CreateToolhelp32SnapshotDllName = "api-ms-win-core-toolhelp-l1-1-0"; /*120*/
- internal const string Process32FirstDllName = "api-ms-win-core-toolhelp-l1-1-0"; /*121*/
- internal const string Process32NextDllName = "api-ms-win-core-toolhelp-l1-1-0"; /*122*/
- internal const string GetACPDllName = "api-ms-win-core-localization-l1-2-0.dll"; /*123*/
- internal const string DeleteServiceDllName = "api-ms-win-service-management-l1-1-0.dll"; /*124*/
- internal const string QueryServiceConfigDllName = "api-ms-win-service-management-l2-1-0.dll"; /*125*/
- internal const string QueryServiceConfig2DllName = "api-ms-win-service-management-l2-1-0.dll"; /*126*/
- internal const string SetServiceObjectSecurityDllName = "api-ms-win-service-management-l2-1-0.dll"; /*127*/
+ internal const string SetConsoleModeDllName = "api-ms-win-core-console-l1-1-0.dll"; /*106*/
+ internal const string SetConsoleScreenBufferSizeDllName = "api-ms-win-core-console-l2-1-0.dll"; /*107*/
+ internal const string SetConsoleTextAttributeDllName = "api-ms-win-core-console-l2-1-0.dll"; /*108*/
+ internal const string SetConsoleWindowInfoDllName = "api-ms-win-core-console-l2-1-0.dll"; /*109*/
+ internal const string WriteConsoleOutputDllName = "api-ms-win-core-console-l2-1-0.dll"; /*110*/
+ internal const string ReadConsoleOutputDllName = "api-ms-win-core-console-l2-1-0.dll"; /*111*/
+ internal const string ScrollConsoleScreenBufferDllName = "api-ms-win-core-console-l2-1-0.dll"; /*112*/
+ internal const string SendInputDllName = "ext-ms-win-ntuser-keyboard-l1-2-1.dll"; /*113*/
+ internal const string GetConsoleCursorInfoDllName = "api-ms-win-core-console-l2-1-0.dll"; /*114*/
+ internal const string SetConsoleCursorInfoDllName = "api-ms-win-core-console-l2-1-0.dll"; /*115*/
+ internal const string ReadConsoleInputDllName = "api-ms-win-core-console-l1-1-0.dll"; /*116*/
+ internal const string GetVersionExDllName = "api-ms-win-core-sysinfo-l1-1-0.dll"; /*117*/
+ internal const string FormatMessageDllName = "api-ms-win-core-localization-l1-2-0.dll"; /*118*/
+ internal const string CreateToolhelp32SnapshotDllName = "api-ms-win-core-toolhelp-l1-1-0"; /*119*/
+ internal const string Process32FirstDllName = "api-ms-win-core-toolhelp-l1-1-0"; /*120*/
+ internal const string Process32NextDllName = "api-ms-win-core-toolhelp-l1-1-0"; /*121*/
+ internal const string GetACPDllName = "api-ms-win-core-localization-l1-2-0.dll"; /*122*/
+ internal const string DeleteServiceDllName = "api-ms-win-service-management-l1-1-0.dll"; /*123*/
+ internal const string QueryServiceConfigDllName = "api-ms-win-service-management-l2-1-0.dll"; /*124*/
+ internal const string QueryServiceConfig2DllName = "api-ms-win-service-management-l2-1-0.dll"; /*125*/
+ internal const string SetServiceObjectSecurityDllName = "api-ms-win-service-management-l2-1-0.dll"; /*126*/
}
}