Skip to content

Commit

Permalink
Porting Ports fix from 0e4909a
Browse files Browse the repository at this point in the history
  • Loading branch information
danmoseley authored and ericstj committed Mar 9, 2022
1 parent 62b44d9 commit 100618b
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/libraries/System.IO.Ports/tests/SerialPort/DosDevices.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Runtime.InteropServices;

namespace System.IO.Ports.Tests
Expand Down Expand Up @@ -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;

Expand Down

0 comments on commit 100618b

Please sign in to comment.