Open jnury opened 6 years ago
Yep, this looks like a PowerShell bug. PowerShell should never crash. Can you supply the exception that is spit out? Or is the first message all you get?
The first message is all I get.
Interesting. Ok! Let me see if I can get a little bit more info during a repro and then we'll move this over to PowerShell/PowerShell as I doubt we'll be able to catch the exception.
Once we're able to do so, we can handle a NoRegisterFoundException
This could also be aproblem with .NET Core itself.
I can apparently replicate this (or at least a very similar) issue on PowerShell 6.1.0-preview.1, and version 0.1.1 of the Microsoft.PowerShell.IoT module. The same error described above by @jnury happens if I try to get the register, but I get a different error just getting the device.
Import-Module Microsoft.PowerShell.IoT
Get-I2CDevice -Id 0x46 #where 0x46 is the correct ID of my device
pwsh will crash and throw the error Unable to select I2C device: Device or resource busy
.
Interestingly, if I do a Get-I2CDevice
for an ID that is just made up, it will simply return an I2CDevice object with whatever FriendlyName and Id values you pass it.
Also, you can crash all the way out of pwsh another way that I found out by accident while verifying the last point.
Import-Module Microsoft.PowerShell.IoT
Get-I2CDevice -Id 911 #Or some other value that isn't valid
pwsh will crash, throwing the error Unable to select I2C device: Invalid argument
.
Thanks for the info @ThmsRynr!
Original PS crash with free(): invalid pointer
error is coming from Unosquare.RaspberryIO.dll
The line 26 ExtendedMessage = Standard.StrError(errorCode);
is calling 'strerror' function from 'libc' library passing 0 (that it gets from Marshal.GetLastWin32Error()
) as an argument.
This should be fixed in Unosquare.RaspberryIO code (I've tried passing -1
as argument as well as commenting out the problem line - both fixed the crash). I'm not sure how we can workaround this at our layer.
@anmenaga Can we open an issue on them? Honestly, it sounds like an easy enough fix that we could even contribute back 👍
as stated on #37 , this code is causing that very same error, although I can't find a pattern for that (aka, the exception is random)
Hi,
If the device provided to Get or Set-I2CRegister commands is not reachable, PowerShell crash with message:
To reproduce (do not connect anything on I2C bus):
PowerShell version: