Menu

#43 Overflow Exception when using DeviceNotifier

v2.2.8
open
nobody
None
7
2014-12-18
2014-02-03
Johni85
No

I want to use the DeviceNotifier but it raises an exception when I plug in or unplug the device:

System.OverflowException was unhandled
HResult=-2146233066
Message=Die arithmetische Operation hat einen Überlauf verursacht.
Source=mscorlib
StackTrace:
bei System.IntPtr.ToInt32()
bei LibUsbDotNet.DeviceNotify.WindowsDeviceNotifier.OnDeviceChange(Message& m)
bei LibUsbDotNet.DeviceNotify.Internal.DevNotifyNativeWindow.WndProc(Message& m)
bei System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
InnerException:

This error only occurs when I set the target framework to 4.5.
When I set the target plattform to x86 it works under .net 4.5 too.

Discussion

  • Johni85

    Johni85 - 2014-02-03

    Correction: the error also occures when I set the target framework to 4.0

     
  • Alessio

    Alessio - 2014-12-10

    I have the same problems, unfortunately it occurs on a Windows 8.1 PC, and not on my Windows 7 laptop. Any news?

     
  • Deepblue978

    Deepblue978 - 2014-12-18

    I noticed the overflow occurs on Win8 or higher because IntPtr has a size of 64bit. Thus casting to 32bits will cause the overflow. Casting to 64 bits will solve this issue.

    Quick and dirty fix:

    Change function OnDeviceChange in file WindowsDeviceNotifier.cs from

    if (m.LParam.ToInt32() != 0)
    

    to

    long tempI = 0;
    try
    {
        tempI = m.LParam.ToInt32();
    }
    catch (System.OverflowException ofe)
    {
        tempI = m.LParam.ToInt64();    
    }
    if (tempI != 0)
    

    and rebuild the dll.

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.