quamotion / madb

SharpAdbClient is a .NET library that allows .NET applications to communicate with Android devices. It provides a .NET implementation of the adb protocol, giving more flexibility to the developer than launching an adb.exe process and parsing the console output.
Apache License 2.0
361 stars 133 forks source link

SyncService "An error occurred while reading a response from ADB" #201

Closed adryzz closed 3 years ago

adryzz commented 3 years ago

So i'm making a program that mounts an android device as a virtual hard drive because the MTP protocol is very slow and i wanna take full advantage of USB 3 on my phone. The easiest way i found is by using this library that i used for a lot of projects and dokan-dotnet Everything is going well but i can't get SyncService to work. i am using the same IAdbSocket as the DeviceMonitor. but when i create the SyncService using Sync = new SyncService(socket, device);, i always get the same AdbException.

Here's all the details about it and here's the code

Am i doing something wrong?

  HResult=0x80131500
  Message=An error occurred while reading a response from ADB: 
  Source=SharpAdbClient
  StackTrace:
   at SharpAdbClient.AdbSocket.ReadAdbResponse()
   at SharpAdbClient.AdbSocket.SetDevice(DeviceData device)
   at SharpAdbClient.SyncService.Open()
   at SharpAdbClient.SyncService..ctor(IAdbSocket socket, DeviceData device)
   at ADBUSBDrive.VirtualDrive..ctor(DeviceData device, IAdbSocket client, Char letter) in D:\source\repos\ADBUSBDrive\ADBUSBDrive\VirtualDrive.cs:line 36
   at ADBUSBDrive.Program.Monitor_DeviceConnected(Object sender, DeviceDataEventArgs e) in D:\source\repos\ADBUSBDrive\ADBUSBDrive\Program.cs:line 42
   at SharpAdbClient.DeviceMonitor.OnDeviceConnected(DeviceDataEventArgs e)
   at SharpAdbClient.DeviceMonitor.UpdateDevices(List 1 devices)
   at SharpAdbClient.DeviceMonitor.ProcessIncomingDeviceData(String result)
   at SharpAdbClient.DeviceMonitor.<DeviceMonitorLoopAsync>d__32.MoveNext()

  This exception was originally thrown at this call stack:
    [External Code]
    ADBUSBDrive.VirtualDrive.VirtualDrive(SharpAdbClient.DeviceData, SharpAdbClient.IAdbSocket, char) in VirtualDrive.cs
    ADBUSBDrive.Program.Monitor_DeviceConnected(object, SharpAdbClient.DeviceDataEventArgs) in Program.cs
    [External Code]

If you need more info, ask and i'll give you all the additional info you need.

adryzz commented 3 years ago

Update: i found out that if the device is already plugged in, i get that exception, while if i plug in the device after the DeviceMonitor started, i get a System.FormatException. Here's the details:

System.FormatException
  HResult=0x80131537
  Message=Input string was not in a correct format.
  Source=mscorlib
  StackTrace:
   at System.Number.StringToNumber(String str, NumberStyles options, NumberBuffer& number, NumberFormatInfo info, Boolean parseDecimal)
   at System.Number.ParseInt32(String s, NumberStyles style, NumberFormatInfo info)
   at SharpAdbClient.AdbSocket.ReadString()
   at SharpAdbClient.AdbSocket.ReadAdbResponseInner()
   at SharpAdbClient.AdbSocket.ReadAdbResponse()
   at SharpAdbClient.AdbSocket.SetDevice(DeviceData device)
   at SharpAdbClient.SyncService.Open()
   at SharpAdbClient.SyncService..ctor(IAdbSocket socket, DeviceData device)
   at ADBUSBDrive.VirtualDrive..ctor(DeviceData device, IAdbSocket client, Char letter) in D:\source\repos\ADBUSBDrive\ADBUSBDrive\VirtualDrive.cs:line 36
   at ADBUSBDrive.Program.Monitor_DeviceConnected(Object sender, DeviceDataEventArgs e) in D:\source\repos\ADBUSBDrive\ADBUSBDrive\Program.cs:line 42
   at SharpAdbClient.DeviceMonitor.OnDeviceConnected(DeviceDataEventArgs e)
   at SharpAdbClient.DeviceMonitor.UpdateDevices(List`1 devices)
   at SharpAdbClient.DeviceMonitor.ProcessIncomingDeviceData(String result)
   at SharpAdbClient.DeviceMonitor.<DeviceMonitorLoopAsync>d__32.MoveNext()

  This exception was originally thrown at this call stack:
    [External Code]
    ADBUSBDrive.VirtualDrive.VirtualDrive(SharpAdbClient.DeviceData, SharpAdbClient.IAdbSocket, char) in VirtualDrive.cs
    ADBUSBDrive.Program.Monitor_DeviceConnected(object, SharpAdbClient.DeviceDataEventArgs) in Program.cs
    [External Code]
adryzz commented 3 years ago

I found the issue. i was using the same IADBSocket as my DeviceMonitor. Creating a new one solved the issue. Sync = new SyncService(new AdbSocket(new IPEndPoint(IPAddress.Loopback, AdbClient.AdbServerPort)), device);