jcurl / RJCP.DLL.SerialPortStream

SerialPortStream is an independent implementation of System.IO.Ports.SerialPort and SerialStream for better reliability and maintainability. Default branch is 2.x and now has support for Mono with help of a C library.
Microsoft Public License
614 stars 196 forks source link

Unhandled exception. System.NullReferenceException #132

Closed ilrom closed 2 years ago

ilrom commented 2 years ago

I use the library, an error occurs only on Linux machines Unhandled exception. System.NullReferenceException: Object reference not set to an instance of an object. at RJCP.IO.Ports.Native.SerialBuffer.RJCP.IO.Ports.Native.ISerialBufferStreamData.get_BytesToRead() at RJCP.IO.Ports.SerialPortStream.HandleEvent(Object state) at System.Threading.QueueUserWorkItemCallback.<>c.<.cctor>b__6_0(QueueUserWorkItemCallback quwi) at System.Threading.ExecutionContext.RunForThreadPoolUnsafe[TState](ExecutionContext executionContext, Action1 callback, TState& state)` Which leads to the failure of my program.

jcurl commented 2 years ago

Thank you for the bug report. Can you tell me the version of the nserial, the library from .net, and the run time you are using?

ilrom commented 2 years ago

Thanks for the quick response SerialPortStream Version="2.3.1" run time 3.1.17

jcurl commented 2 years ago

I've just posted version 2.4.0 which has changes for handling exceptions in the callbacks. Perhaps this fixes your problem?

If the problem persists, you'll need to enable logging (e.g. console logging), and inject that logger into the SerialPortStream constructor.

ilrom commented 2 years ago

Thanks, I will test and answer whether it helped me.

Muximize commented 2 years ago

@ilrom Does 2.4.0 fix your issue?

jcurl commented 2 years ago

I analysed the code again, and the problem should not occur with 2.4.0. The callback for the handling of events has now a try/catch block (which would cause .NET Core program to exit, instead of causing an exception).

I'll leave this ticket open for a few days, otherwise I'll close it as fixed in 2.4.0 which is now a NuGet package for a month or so.