Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

System.BadImageFormatException: Read out of bounds. #765

Open
juliocarreira opened this issue Oct 27, 2023 · 2 comments
Open

System.BadImageFormatException: Read out of bounds. #765

juliocarreira opened this issue Oct 27, 2023 · 2 comments

Comments

@juliocarreira
Copy link

Hey! I'm starting to use Plugin.BLE and I wrote a simple program to scan BLE devices, but for some reason it crashes when I start to find devices (await Adapter.StartScanningForDevicesAsync( );)

Thanks in advance for any clues that help me solve it.
Yours sincerely

Steps to reproduce

using Plugin.BLE;
using Plugin.BLE.Abstractions.Contracts;
using System.Collections.ObjectModel;
using Debug = System.Diagnostics.Debug;

namespace MauiAppBLEV1;

public partial class MainPage : ContentPage
{

readonly IBluetoothLE Ble = CrossBluetoothLE.Current;
readonly IAdapter Adapter = CrossBluetoothLE.Current.Adapter;

public ObservableCollection<String> Devices;
public ObservableCollection<IDevice> Device;


public MainPage()
{
	InitializeComponent();

    Ble.StateChanged += (s,e) =>
    {
        Debug.WriteLine("State: " + e.NewState);
    };


    Adapter.DeviceDiscovered += async (s,a) =>
    {
        Debug.WriteLine("Device: " + a.Device.ToString( ));
        try
            {
            Devices.Add(a.Device.ToString( ));
            Device.Add(a.Device);
            await Adapter.ConnectToDeviceAsync(a.Device);
            var service = await a.Device.GetServicesAsync( );
            Debug.WriteLine(service.ToString( ));
            Debug.WriteLine(Devices + " " + Device);
            }
        catch(Exception ex)
            {
            Debug.WriteLine(ex);
            }

    };

    Adapter.DeviceBondStateChanged += (s,e) =>
    {
        Debug.WriteLine(e.State + " " + e.Address);
    };

    Adapter.DeviceConnected += (s,e) =>
    {
        Debug.WriteLine(e.Device.ToString( ));
    };

    }


private void ButtonBLETest_Clicked(object sender,EventArgs e)
    {
        StartConn();
    }

public async void StartConn()
    {
    Debug.WriteLine(Ble.State);
    try
        {
        await Adapter.StartScanningForDevicesAsync( );
        }
    catch(Exception ex)
        {
        Debug.WriteLine(ex);
        }
    }



}

Expected behavior

Get the list of BLE devices

Actual behavior

System.BadImageFormatException: Read out of bounds.

Crashlog

[OpenGLRenderer] Davey! duration=4664ms; Flags=0, FrameTimelineVsyncId=28142, IntendedVsync=2140444609546, Vsync=2145094609360, InputEventId=-539398772, HandleInputStart=2145100340013, AnimationStart=2145101394752, PerformTraversalsStart=2145102048086, DrawStart=2145102496471, FrameDeadline=2140477942878, FrameInterval=2145100204179, FrameStartTime=16666666, SyncQueued=2145103465898, SyncStart=2145103858294, IssueDrawCommandsStart=2145103927825, SwapBuffers=2145104553502, FrameCompleted=2145109194961, DequeueBufferDuration=18073, QueueBufferDuration=1429843, GpuCompleted=2145109194961, SwapBuffersCompleted=2145106315534, DisplayPresentTime=-5476376617024650016,
Read out of bounds.
System.BadImageFormatException: Read out of bounds.
at System.Reflection.Throw.OutOfBounds()
at System.Reflection.Metadata.Ecma335.MethodDebugInformationTableReader.GetDocument(MethodDebugInformationHandle handle)
at Mono.Debugging.Soft.PortablePdbData.GetDebugInfoFromPdb(MethodMirror method) in D:\a_work\1\s\External\debugger-libs\Mono.Debugging.Soft\PortablePdbData.cs:line 186
at Mono.Debugging.Soft.SoftDebuggerBacktrace.CreateStackFrame(StackFrame frame, Int32 frameIndex) in D:\a_work\1\s\External\debugger-libs\Mono.Debugging.Soft\SoftDebuggerBacktrace.cs:line 157
at Mono.Debugging.Soft.SoftDebuggerBacktrace.GetStackFrames(Int32 firstIndex, Int32 lastIndex) in D:\a_work\1\s\External\debugger-libs\Mono.Debugging.Soft\SoftDebuggerBacktrace.cs:line 128
at Mono.Debugging.Client.Backtrace.GetFrame(Int32 index, Int32 fetchMultipleCount) in D:\a_work\1\s\External\debugger-libs\Mono.Debugging\Mono.Debugging.Client\Backtrace.cs:line 61
at Mono.Debugging.Client.Backtrace..ctor(IBacktrace serverBacktrace) in D:\a_work\1\s\External\debugger-libs\Mono.Debugging\Mono.Debugging.Client\Backtrace.cs:line 27
at Mono.Debugging.Soft.SoftDebuggerSession.HandleBreakEventSet(Event[] es, Boolean dequeuing) in D:\a_work\1\s\External\debugger-libs\Mono.Debugging.Soft\SoftDebuggerSession.cs:line 2186
at Mono.Debugging.Soft.SoftDebuggerSession.EventHandler() in D:\a_work\1\s\External\debugger-libs\Mono.Debugging.Soft\SoftDebuggerSession.cs:line 1802

Configuration

**Version of the Plugin:**3.0.0

Platform: Android 12.0 API 31

Device: Samsung SM-M515F

@smsissuechecker
Copy link

Hi @juliocarreira,

I'm the friendly issue checker.
Thanks for using the issue template 🌟
I appreciate it very much. I'm sure, the maintainers of this repository will answer, soon.

@janusw
Copy link
Member

janusw commented Nov 18, 2023

System.BadImageFormatException: Read out of bounds.

This sounds very strange. From https://learn.microsoft.com/de-de/dotnet/api/system.badimageformatexception:

The exception that is thrown when the file image of a dynamic link library (DLL) or an executable program is invalid.

So you're doing something weird, apparently. Maybe the above page helps you to understand why this happens. I strongly doubt that this is caused by Plugin.BLE and I'm afraid we cannot help you much here ...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants