Author Topic: Unhandeled exception in Driver Service  (Read 2492 times)

valtonen

  • Full Member
  • ***
  • Posts: 217
    • View Profile
Unhandeled exception in Driver Service
« on: September 27, 2010, 03:53:10 am »
I got an unhandeled exception in Driver Service when trying to use COM1 serial port (not USB-serial converter):

Code: [Select]
Date:     27.9.2010
Time:     13:46:52
Severity: Fatal
Source:   DriverService
Computer: SUKKULA
Context Type: None
Context Name:
Description:
An unhandled exception occurred in the Elve Driver Service.

System.ObjectDisposedException: Safe handle has been closed
   at Microsoft.Win32.UnsafeNativeMethods.GetOverlappedResult(SafeFileHandle hFile, NativeOverlapped* lpOverlapped, Int32& lpNumberOfBytesTransferred, Boolean bWait)
   at System.IO.Ports.SerialStream.EventLoopRunner.WaitForCommEvent()
   at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
   at System.Threading.ExecutionContext.runTryCode(Object userData)
   at System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode code, CleanupCode backoutCode, Object userData)
   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Threading.ThreadHelper.ThreadStart()

ObjectDisposedException: Safe handle has been closed

System.ObjectDisposedException: Safe handle has been closed
   at Microsoft.Win32.UnsafeNativeMethods.GetOverlappedResult(SafeFileHandle hFile, NativeOverlapped* lpOverlapped, Int32& lpNumberOfBytesTransferred, Boolean bWait)
   at System.IO.Ports.SerialStream.EventLoopRunner.WaitForCommEvent()
   at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
   at System.Threading.ExecutionContext.runTryCode(Object userData)
   at System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode code, CleanupCode backoutCode, Object userData)
   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Threading.ThreadHelper.ThreadStart()

The port was not accessible as described by this log item:

Code: [Select]
Date:     27.9.2010
Time:     13:46:52
Severity: Error
Source:   DriverService
Computer: SUKKULA
Context Type: None
Context Name:
Description:
Failed to start device 'Scars'.

UnauthorizedAccessException: Access to the port 'COM1' is denied.

System.UnauthorizedAccessException: Access to the port 'COM1' 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 CodecoreTechnologies.Elve.DriverFramework.Communication.SerialCommunication.Open()
   at SmartHomeDrivers.Scars._serialInit() in \\kataja\LIPS\Alkkari2\SDK\Smart Home Drivers\Scars\Scars.cs:line 215
   at SmartHomeDrivers.Scars.StartDriver(Dictionary`2 configFileData) in \\kataja\LIPS\Alkkari2\SDK\Smart Home Drivers\Scars\Scars.cs:line 194
   at DriverService.DriverService2.createAndStartDevice(Object parameter)

And the reason for this error was that I tried to open the port twice. :/

Code: [Select]
            _serial.StartConnectionMonitor();
            _serial.Open();

-Miika
« Last Edit: September 27, 2010, 04:05:18 am by valtonen »

John Hughes

  • Administrator
  • Hero Member
  • *****
  • Posts: 2851
    • View Profile
    • Codecore Technologies
Re: Unhandeled exception in Driver Service
« Reply #1 on: September 28, 2010, 08:55:21 am »
Thanks for testing the interim version, this should be fixed now (for the next release).
John Hughes
Codecore Technologies

John Hughes

  • Administrator
  • Hero Member
  • *****
  • Posts: 2851
    • View Profile
    • Codecore Technologies
Re: Unhandeled exception in Driver Service
« Reply #2 on: November 28, 2011, 01:17:00 pm »
I may have found a reliable workaround for this Microsoft .NET bug. Looking into it soon...
John Hughes
Codecore Technologies