Device.Net
Device.Net copied to clipboard
Always get SEHException with visual studio debug
Describe the issue
I always got System.Runtime.InteropServices.SEHException if i run my app (test console app) with visual studio debugger. If i run without debugger, this error never appear. I suspect that it is thrown when im trying to dispose the IDevice object:
m_deviceService.Device.Dispose();
or even with this code:
await DeviceManager.Current.GetConnectedDeviceDefinitionsAsync(null);
Where m_deviceService is an instance of BulkIOService. I dont know which part of my code causes this error because visual studio says that it is executing external code (see screenshot below). I dont know if this is a real issue but it is quite annoying to always get it when debugging. Any idea?
Screenshots

Platform: Windows 10 Version: 3.0.0 beta 2
@realivanjx thanks for reporting. Yes, I've seen this one before. I'm not sure if it's a real issue myself...
Could you try including the device.net projects in your solution directly? Instead of the NuGet. I need to see the exact line.
I dont think that it will show the line either because i think it errors in the c++ api you are using.
@realivanjx you're probably right. I had the same issue. Do you have "enable just my code" turned on? Check that it debugging options.
Yes it is on already
@realivanjx the only thing I can recommend is to turn off the exception in the debugging options. I will look out for it and try to find out which API is causing the problem.
i have tried to disable the exception in debugging options but that doesnt work. the app also keeps closing when i hit continue on visual studio after the error. this makes me impossible to debug the app now
never got this issue when running without debugging though
is there any updates on this issue?
@realivanjx I probably won't fix this issue because it doesnt cause any serious problems that I know about.
It's only an annoyance. As far as I know, it only causes an issue for debugging right?
yea, but it affects me so that i cant debug the app at all now
so for me it kinda serious
maybe this could be the issue with visual studio itself? because this only happens while debugging though

Same problem here... probably it has something to do with SafeFileHandles, as VS was trying to locate source code for that (if Just My Code in debugger settings wasn't enabled).
@st-arnold you're probably right. I'd prefer that everything were converted to safe handles if possible
I can confirm that this only happens during a debugger is attached. You can easily reproduce the problem when you start for instance a reading process from a device and unplug the USB during that. Reattach the USB and start again a reading process. Then this SEHException occurs. As said, when a debugger is attached to the app crashes. Without one it running without any issue.
@st-arnold @datoml @realivanjx
This issue may have been because of an issue with dispose. Any chance you could try the latest version to see if you still get the issue?
https://www.nuget.org/packages/Usb.Net/4.0.8-alpha
I still have this issue using Usb.Net 4.0.9-alpha and Rider for debugging. The stack trace references SafeHandle.Finalize() (and none of my code). Disabling external code debugging didn't seem to solve the issue.
@NorbiPeti yep. No idea what this or how to fix it. Suggestions welcome.
@NorbiPeti have you enabled "Just My Code" in visual studio debugging options?