.NET MAUI app close when Bluetooth keyboard is connected or disconnect

NickNN 40 Reputation points
2024-11-23T23:28:22.9733333+00:00

Hi, I have an app that closes when I connect or disconnect the Bluetooth keyboard to the device. Then I launch it again and it works and the keyboard can be used, it seems that it only has this behavior on changes (if it is connected and I turn off the keyboard, the connection is lost and it also closes). The error that it shows in the console is:

[ERROR] FATAL UNHANDLED EXCEPTION: System.ObjectDisposedException: Cannot access a closed Stream.
[mono-rt]    at System.IO.UnmanagedMemoryStream.EnsureNotClosed()
[mono-rt]    at System.IO.UnmanagedMemoryStream.ReadCore(Span`1 buffer)
[mono-rt]    at System.IO.UnmanagedMemoryStream.Read(Byte[] buffer, Int32 offset, Int32 count)
[mono-rt]    at Android.Runtime.InputStreamAdapter.Read(Byte[] bytes, Int32 offset, Int32 length) in /Users/runner/work/1/s/xamarin-android/src/Mono.Android/Android.Runtime/InputStreamAdapter.cs:line 38
[mono-rt]    at Java.IO.InputStream.n_Read_arrayBII(IntPtr jnienv, IntPtr native__this, IntPtr native_b, Int32 off, Int32 len) in /Users/runner/work/1/s/xamarin-android/src/Mono.Android/obj/Release/net8.0/android-34/mcw/Java.IO.InputStream.cs:line 229
[mono-rt]    at Android.Runtime.JNINativeWrapper.Wrap_JniMarshal_PPLII_I(_JniMarshal_PPLII_I callback, IntPtr jnienv, IntPtr klazz, IntPtr p0, Int32 p1, Int32 p2) in /Users/runner/work/1/s/xamarin-android/src/Mono.Android/Android.Runtime/JNINativeWrapper.g.cs:line 275

Thanks

.NET MAUI
.NET MAUI
A Microsoft open-source framework for building native device applications spanning mobile, tablet, and desktop.
4,059 questions
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.