title: Cannot access serial port during debugging
body: <p>This is my first SO question so please correct me where I am not supplying enough or correct information.</p>
  
  <p>I'm interfacing two RFID tag readers via RS232 ports on a FTDI serial to USB hub to my program.  The program runs perfectly outside VS2010, but I cannot debug the code.  The program starts fine during debugging, but as soon as I bring a tag within reading proximity I get an error.  This only happens during debugging.</p>
  
  <p>The error:</p>
  
  <pre><code>Error Opening Serial Port COM9
  
  System.UnauthorizedAccessException: Access to the port 'COM9' is denied.
  
     at System.IO.Ports.InternalResources.WinIOError(Int32 errorCode, String str)
  
     at System.IO.Ports.SerialStream..ctor(String portName, Int32 baudRate, Parity parity, Int32 dataBits, StopBits stopBits, Int32 readTimeout, Int32 writeTimeout, Handshake handshake, Boolean dtrEnable, Boolean rtsEnable, Boolean discardNull, Byte parityReplace)
  
     at System.IO.Ports.SerialPort.Open()
  
     at Tag_Reader.COMs.openPort(String sPortName) in C:\XXX\Tag_Reader\COMs.cs:line 36
  </code></pre>
  
  <p>COMs.cs:line 36:</p>
  
  <pre><code> _port.PortName = sPortName;
   _port.BaudRate = 9600;
   _port.DataBits = 8;
   _port.Parity = Parity.None;
   _port.StopBits = StopBits.One;
   _port.ReadTimeout = 500;
   _port.WriteTimeout = 500;
   _port.Open();
  </code></pre>
  
  <p>I would appreciate any help!  As mentioned above the programs runs without a glitch if I run the .exe outside VS.</p>
  
  <p><strong>EDIT:</strong>
  This error <strong>only occurs during debug</strong> and <strong>only</strong> when there is data being streamed from the tag reader (when a tag is brought within the reader's reading proximity). This indicates that the port setup is correct. </p>