.NET Semaphore Creation Fails with IoException Error in Win 2008

The following code does not work for me in Windows 2008. It succeeds in Win7.

return new Semaphore(1, 1, "my-test-semaphore");

I get the following error:

System.IO.IOException: The specified port does not exist.
  at System.IO.Ports.InternalResources.WinIOError(Int32 errorCode, String str)
  at System.IO.Ports.InternalResources.WinIOError()
  at System.Threading.Semaphore..ctor(Int32 initialCount, Int32 maximumCount, String name)
  at Throttle.Program.CreateSemaphore(String passthroughApplication)
  at Throttle.Program.Main(String[] args)

I searched and cannot find an explanation. Does anyone have any idea?

+4
source share
1 answer

You are a victim of error in error messages. The exception message is strange because the WinIOError () method it uses is shared with the SerialPort class. When the Windows error code is 2 (file not found) or 3 (path not found), you will receive an exception message that is only suitable for the serial port. Therefore, weirdo's message "The specified port does not exist."

, . , , "my-test-semaphore". , , Windows. "backslashes\\are not okay".

.

+7

All Articles