diff --git a/src/libraries/System.IO.Ports/tests/SerialPort/DosDevices.cs b/src/libraries/System.IO.Ports/tests/SerialPort/DosDevices.cs index 3fe9493c0a30e..2d74327f97eb0 100644 --- a/src/libraries/System.IO.Ports/tests/SerialPort/DosDevices.cs +++ b/src/libraries/System.IO.Ports/tests/SerialPort/DosDevices.cs @@ -3,6 +3,7 @@ using System.Collections; using System.Collections.Generic; +using System.ComponentModel; using System.Runtime.InteropServices; namespace System.IO.Ports.Tests @@ -127,14 +128,20 @@ private static char[] CallQueryDosDevice(string name, out int dataSize) buffer = new char[buffer.Length * 2]; dataSize = QueryDosDevice(null, buffer, buffer.Length); } + else if (lastError == ERROR_ACCESS_DENIED) // Access denied eg for "MSSECFLTSYS" - just skip + { + dataSize = 0; + break; + } else { - throw new Exception("Unknown Win32 Error: " + lastError); + throw new Exception($"Error {lastError} calling QueryDosDevice for '{name}' with buffer size {buffer.Length}. {new Win32Exception((int)lastError).Message}"); } } return buffer; } + public const int ERROR_ACCESS_DENIED = 5; public const int ERROR_INSUFFICIENT_BUFFER = 122; public const int ERROR_MORE_DATA = 234;