1

Topic: HidSharp RegisterClass failed

I'm seeing an error on one machine where it throws an InvalidOperation Exception

  at HidSharp.Platform.Windows.WinHidManager.Run(Action readyCallback)
   at HidSharp.Platform.HidManager.RunImpl(Object readyEvent)
   at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Threading.ThreadHelper.ThreadStart(Object obj)</StackTrace><ExceptionString>System.InvalidOperationException: HidSharp RegisterClass failed.
   at HidSharp.Platform.Windows.WinHidManager.Run(Action readyCallback)
   at HidSharp.Platform.HidManager.RunImpl(Object readyEvent)
   at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Threading.ThreadHelper.ThreadStart(Object obj)

Is there any known issues around this?

2

Re: HidSharp RegisterClass failed

Shouldn't be. What OS? Could you get line numbers with the debug version? Thanks!

3

Re: HidSharp RegisterClass failed

It was WIndows 10, but I know it was my error now, it appears we loaded two versions of the HIDSharp.dll by mistake and it looks like the second attempt to register the window failed and rippled to an app-domain failure.

We're now working on ensuring we don't load two versions which will sort the issue out.

4

Re: HidSharp RegisterClass failed

Further work on this has led to me reluctantly having to patch the code, as there are scenarios where we need to load two versions for different purposes in the same app-domain.

A quick change to WinHidManager allows this:

     protected override void Run(Action readyCallback)
        {
            string className = "HidSharpDeviceMonitor" + Guid.NewGuid().ToString("N");

            NativeMethods.WindowProc windowProc = DeviceMonitorWindowProc;
            var wc = new NativeMethods.WNDCLASS() { ClassName = className, WindowProc = windowProc };
            RunAssert(0 != NativeMethods.RegisterClass(ref wc), "HidSharp RegisterClass failed.");

Mike