none
Error: Access to the port 'COM4' is denied RRS feed

  • Question

  • Presently, I am developing a Windows Service that receives data via a serial port to USB converter on Windows Foundation Server 2012. If I plug the serial port to USB converter into one particular port, it works fine, but if I plug the serial port to USB converter into a different USB port on the computer, I receive the following error repeatedly:

    A first chance exception of type 'System.UnauthorizedAccessException' occurred in System.dll

    Error: Access to the port 'COM4' 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 MySvc.Data

    SourceSerialPort.MonitorDataSource(Object processor) in d:\DevProjects\E3\My Server\MySvc3Svc\MySvcSvc\MySerialPort.cs:line 312

    Here is what I'm getting if I use Sysinternal's handle.exe:

    MySvc.vshost.exe pid: 3484 WIN-8K0PETTOH2C\Administrator

       C4: Section       \...\Cor_SxSPublic_IPCBlock

       C8: Section       \BaseNamedObjects\Cor_Private_IPCBlock_v4_3484

      220: File  (R--)   D:\Windows\assembly\pubpol12.dat

      224: File  (R-D)   D:\Windows\assembly\GAC_MSIL\Microsoft.VisualStudio.HostingProcess.Utilities\12.0.0.0__b03f5f7f11d50a3a\Microsoft.VisualStudio.HostingProcess.Utilities.dll

      248: File  (R-D)   D:\Windows\assembly\GAC_MSIL\Microsoft.VisualStudio.HostingProcess.Utilities.Sync\12.0.0.0__b03f5f7f11d50a3a\Microsoft.VisualStudio.HostingProcess.Utilities.Sync.dll

      254: File  (R-D)   D:\Windows\assembly\GAC_MSIL\Microsoft.VisualStudio.Debugger.Runtime\12.0.0.0__b03f5f7f11d50a3a\Microsoft.VisualStudio.Debugger.Runtime.dll

      260: Section       \Sessions\2\BaseNamedObjects\__FEQA_IPCINFO__d9c

      284: Section       \BaseNamedObjects\__ComCatalogCache__

      2C0: Section       \RPC Control\DSECD9C

      3AC: File  (R-D)   D:\DevProjects\E3\My Server\MySvc\MySvc\bin\Debug\MySvc.exe

      3C8: File  (RW-)   D:\Windows\WinSxS\amd64_microsoft.windows.common-controls_6595b64144ccf1df_5.82.9600.17415_none_34aa3313958e7a52

      3CC: File  (RW-)   D:\DevProjects\E3\My Server\MySvc\MySvc\bin\Debug

      3D8: Section       \Sessions\2\Windows\Theme2829816806

      3E4: Section       \Windows\Theme2907181908

      420: File  (R-D)   D:\DevProjects\E3\My Server\MySvc\MySvc\bin\Debug\ServiceProcess.Helpers.dll

      424: File  (R-D)   D:\DevProjects\E3\My Server\MySvc\MySvc\bin\Debug\E3CommonObjects.dll

      428: File  (R-D)   D:\Windows\System32\en-US\user32.dll.mui

      7D4: File  (R-D)   D:\DevProjects\E3\My Server\MySvc\MySvc\bin\Debug\ReactiveUI.dll

      7D8: File  (R-D)   D:\DevProjects\E3\My Server\MySvc\MySvc\bin\Debug\System.Reactive.dll

      7E0: File  (R-D)   D:\DevProjects\E3\My Server\MySvc\MySvc\bin\Debug\ReactiveUI.Xaml.dll

      7E8: File  (R-D)   D:\DevProjects\E3\My Server\MySvc\MySvc\bin\Debug\System.Reactive.Windows.Threading.dll

      810: Section       \Sessions\2\BaseNamedObjects\windows_shell_global_counters

      8CC: File  (RW-)   D:\Windows\System32

      90C: File  (R-D)   D:\Windows\System32\en-US\msctfui.dll.mui

      944: File  (R-D)   D:\DevProjects\E3\My Server\MySvc\MySvc\bin\Debug\E3DataAccessLayer.dll

      960: File  (R-D)   D:\DevProjects\E3\My Server\MySvc\MySvc\bin\Debug\log4net.dll

      964: Section       \BaseNamedObjects\netfxcustomperfcounters.1.0.net data provider for sqlserver

      980: Section       \BaseNamedObjects\NLS_CodePage_1252_3_2_0_0

      990: File  (RW-)   D:\Users\Administrator\AppData\Local\Temp\2\DataSourceLogFile.txt

      9A8: File  (R-D)   D:\Windows\Microsoft.NET\assembly\GAC_64\System.EnterpriseServices\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.EnterpriseServices.Wrapper.dll

      9AC: File  (R-D)   D:\Windows\Microsoft.NET\assembly\GAC_64\System.Transactions\v4.0_4.0.0.0__b77a5c561934e089\System.Transactions.dll

      A58: File  (RW-)   D:\Windows\WinSxS\amd64_microsoft.vc80.crt_1fc8b3b9a1e18e3b_8.0.50727.8428_none_88dcdb0b2fb19957

      A90: Section       \BaseNamedObjects\NLS_CodePage_1252_3_2_0_0

      C10: File  (R-D)   D:\DevProjects\E3\My Server\MySvc\MySvc\bin\Debug\MySvc.pdb

    Does anyone have any ideas as to why my service is receiving this error, and how to resolve it?  How can I determine if a different process already has a handle on this serial port?  Presently, I am running as local Administrator so why would I be receiving UnauthorizedAccessException?



    • Edited by Roger2015 Thursday, February 5, 2015 8:16 PM added further question
    Thursday, February 5, 2015 8:10 PM

Answers

  • To resolve the issue, I shut down both the receiving laptop and sending laptop, and then restarted them. It may have been a configuration issue (i.e., COM4 should have been COM5) or perhaps I was not shutting down the service properly so that Dispose did not get called on the SerialPort objects.
    • Marked as answer by Roger2015 Thursday, February 5, 2015 9:29 PM
    Thursday, February 5, 2015 9:29 PM

All replies

  • To resolve the issue, I shut down both the receiving laptop and sending laptop, and then restarted them. It may have been a configuration issue (i.e., COM4 should have been COM5) or perhaps I was not shutting down the service properly so that Dispose did not get called on the SerialPort objects.
    • Marked as answer by Roger2015 Thursday, February 5, 2015 9:29 PM
    Thursday, February 5, 2015 9:29 PM
  • Hello Roger,

    I'm glad to hear that you got it working. and thank you for sharing your solutions & experience here. It will be very beneficial for other community members who have similar questions.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Friday, February 6, 2015 1:49 AM
    Moderator