PORTS Forum

Ports and Interfaces => USB => Topic started by: Frank Neumann on December 03, 2019, 07:50:10 am

Title: Generic HID example work only under .NET Framework 2.0
Post by: Frank Neumann on December 03, 2019, 07:50:10 am
For 4 days I try to find out why the code (Generic HID 50) does not work with my Visual Studio settings! :-)

Now today I found out that the sample code of Jan Axelson is based on the framework 2.0, where I set mine to 4.5.

Who can tell me what I need to change in the code so that the example of Jan Axelson also works under the Framework 4.5?

thank you in advance
Frank Neumann
Title: Re: Generic HID example work only under .NET Framework 2.0
Post by: Jan Axelson on December 03, 2019, 09:54:28 am
Where is the code failing?
Title: Re: Generic HID example work only under .NET Framework 2.0
Post by: Frank Neumann on December 03, 2019, 10:10:22 am
Hi Mrs. Axelson,

if I switch the Targetframework from 2.0 to 4.5 then I get the message:
Quote
Eine Ausnahme (erste Chance) des Typs "System.OverflowException" ist in GenericHid.exe aufgetreten.
An exception (first chance) of the System.OverflowException type has occurred in GenericHid.exe.
And my Hardware can not switched.

Till Framework 3.5 is OK, over 4.0 I get this message.
Title: Re: Generic HID example work only under .NET Framework 2.0
Post by: Jan Axelson on December 03, 2019, 10:36:11 am
What in the code triggers the exception?

I can run the code under .NET 4.0, haven't tried higher.

Also see:

https://social.msdn.microsoft.com/Forums/lync/en-US/394ce5ba-b2fa-4046-af17-9904c00cd326/moving-to-net-46-caused-an-overflow-exception?forum=csharpgeneral
Title: Re: Generic HID example work only under .NET Framework 2.0
Post by: Jan Axelson on December 03, 2019, 11:29:21 am
Try setting Build > Configuration Manager > x86
Title: Re: Generic HID example work only under .NET Framework 2.0
Post by: Frank Neumann on December 03, 2019, 11:32:38 am
I have already tried, unfortunately the same behavior
Title: Re: Generic HID example work only under .NET Framework 2.0
Post by: Jan Axelson on December 03, 2019, 12:04:50 pm
Changing the build worked for me. If you can find where the code is failing we might be able to help.
Title: Re: Generic HID example work only under .NET Framework 2.0
Post by: Frank Neumann on December 03, 2019, 12:31:30 pm
How can I determine where exactly that fails?

Title: Re: Generic HID example work only under .NET Framework 2.0
Post by: Jan Axelson on December 03, 2019, 02:29:21 pm
Use breakpoints, single stopping.

https://stackify.com/debugging-tips-net/
Title: Re: Generic HID example work only under .NET Framework 2.0
Post by: Frank Neumann on December 03, 2019, 04:36:49 pm
Hallo,

at this row stopped the debugger

Quote

  fileStreamdevicedata.BeginRead(inputReportBuffer, 0, inputReportBuffer.Length, New AsyncCallback(AddressOf GetInputReportData), inputReportBuffer)

Error msg:
Quote
Eine Ausnahme (erste Chance) des Typs "System.AccessViolationException" ist in mscorlib.dll aufgetreten.

I have set Framework on 4,5
And CPU = X86
Title: Re: Generic HID example work only under .NET Framework 2.0
Post by: Jan Axelson on December 03, 2019, 07:50:48 pm
did you have a breakpoint there? See

https://stackoverflow.com/questions/24604941/apm-and-the-unresolved-system-accessviolationexception-mystery-on-breakpoints
Title: Re: Generic HID example work only under .NET Framework 2.0
Post by: Frank Neumann on December 04, 2019, 12:36:36 am
Good morning,

no I have not set a breakpoint.
Title: Re: Generic HID example work only under .NET Framework 2.0
Post by: Jan Axelson on December 04, 2019, 09:17:33 am
I'm not sure when I'll have time to look at this in more detail but will post if I have a fix. In the meantime, suggest using an earlier edition of .NET that works.
Title: Re: Generic HID example work only under .NET Framework 2.0
Post by: Frank Neumann on December 05, 2019, 12:06:26 am
Hi,

now I found something.
If I set the Framework on 4,5 then the following Method shows an error.
See attachments

And this error will generated from
Quote
fileStreamdevicedata.BeginRead(inputReportBuffer, 0, inputReportBuffer.Length, New AsyncCallback(AddressOf GetInputReportData), inputReportBuffer)

Title: Re: Generic HID example work only under .NET Framework 2.0
Post by: Jan Axelson on December 05, 2019, 09:39:36 am
You could try looking at the InnerException:

https://docs.microsoft.com/en-us/dotnet/api/system.reflection.targetinvocationexception?redirectedfrom=MSDN&view=netframework-4.8