powered-up icon indicating copy to clipboard operation
powered-up copied to clipboard

"System.NullReferenceException: Object reference not set to an instance of an object." during "Discover Ports. Receiving Messages ..." when using CLI

Open voomdoon opened this issue 2 years ago • 4 comments

There is a NullReferenceException during Discover Ports. Receiving Messages ... using latest master branch

>poweredup device list
Scan Started. Please select the Hub (using a number keys or 'q' to terminate):
1: DuploTrainBase (with address <ADDRESS>)
1
Selected DuploTrainBase with key 1
Discover Ports. Receiving Messages ...
System.NullReferenceException: Object reference not set to an instance of an object.
   at SharpBrick.PoweredUp.Bluetooth.BluetoothKernel.ConnectAsync() in /home/runner/work/powered-up/powered-up/src/SharpBrick.PoweredUp/Bluetooth/BluetoothKernel.cs:line 29
   at SharpBrick.PoweredUp.Protocol.LegoWirelessProtocol.ConnectAsync(SystemType knownSystemType) in /home/runner/work/powered-up/powered-up/src/SharpBrick.PoweredUp/Protocol/LegoWirelessProtocol.cs:line 49
   at SharpBrick.PoweredUp.Cli.DevicesList.ExecuteAsync(SystemType knownSystemType) in /home/runner/work/powered-up/powered-up/src/SharpBrick.PoweredUp.Cli/Commands/DevicesList.cs:line 29
   at SharpBrick.PoweredUp.Cli.Program.<>c__DisplayClass4_2.<<Main>b__6>d.MoveNext() in /home/runner/work/powered-up/powered-up/src/SharpBrick.PoweredUp.Cli/Program.cs:line 78

Environment:

  • Windows 10
  • .NET: https://aka.ms/dotnet-core-applaunch?framework=Microsoft.NETCore.App&framework_version=3.1.0&arch=x64&rid=win10-x64

voomdoon avatar Apr 20 '22 16:04 voomdoon

on second attempt its working, not sure how to reproduce

voomdoon avatar Apr 20 '22 17:04 voomdoon

hah ... probably the device switched or just did not do what it should or the data was gliberrish in the air of during the wireless connection .... which is all fine. The code deserves some more love at

https://github.com/sharpbrick/powered-up/blob/master/src/SharpBrick.PoweredUp/Bluetooth/BluetoothKernel.cs#L29

Basically we do three calls to external resources and follow the happy path ... pretty stupid and not very defensively programmed.

I am a bit tired right now due to private stuff .... do you want to take a shot at improving this function?

tthiery avatar Apr 20 '22 21:04 tthiery

I am just doing my first steps with C#, so would need some time...

voomdoon avatar Apr 20 '22 21:04 voomdoon

no worries. I have time ;) and can review code ;)

tthiery avatar Apr 20 '22 21:04 tthiery