Azure / azure-iot-sdk-csharp

A C# SDK for connecting devices to Microsoft Azure IoT services
Other
466 stars 493 forks source link

DeviceClient ReceiveAsync doesn't work with Mqtt, Xamarin Android #249

Closed FinitelyFailed closed 3 years ago

FinitelyFailed commented 6 years ago

I have tried: Xamarin.Forms Version 2.5.0.91635, but I have tried every version down to 2.3. Microsoft.Azure.Devices.Client Version 1.4.0,1.5.0, 1.5.1,1.5.2 and 1.6.0-preview.

Description of the issue:

When I try to receive a message from the IOT-hub I do not get anything when I am using Mqtt, Http1 works fine as well as Amqp.

Code sample exhibiting the issue:

_iotDeviceClient = DeviceClient.CreateFromConnectionString(connectionString, transportType: TransportType.Mqtt); _iotDeviceClient.ReceiveAsync().ContinueWith(task => { if (!task.IsFaulted) { var msg = task.Result; } });

When I set a breakpoint on the if-statement and run the code on a device and send a message from the IOT-hub the breakpoint is never triggered. However if I use Http1 or Amqp it triggers. It seems to work fine on iOS and UWP but not on Android. A very few times it triggers but then the task has faulted with a timeout-exception.

acambitsis commented 6 years ago

Hi there - have you managed to make headway on the above? We are seemingly having the same problem. Thanks, Andreas.

CIPop commented 6 years ago

Thanks @FinitelyFailed and @acambitsis for reporting this. We didn't get a chance to look into this issue yet. My understanding was that Xamarin/Android is blocked by https://github.com/Azure/azure-iot-sdk-csharp/issues/197. Are you able to compile a "Release" version?

davidmaiden commented 6 years ago

Hi - I'm having this issue too. Any idea when there will be any progress on this? I'm not sure if its related, but problems I was having with Xamarin/Android and using PackageReference based projects when referencing Microsoft.Azure.Devices.Client (as mentioned in #197) appear to have been solved with the release of VS2017 15.5.4 (yesterday)

nrandell commented 6 years ago

I'm also seeing this. Latest visual studio 15.7.3, latest libraries (Devices.client 1.7.1). Able to build a release mode. AMQP works ok. MQTT just doesn't seem to send or receive.

Here's my sending error - if someone can show me an easy way to get dotnetty logging running, I'm happy to add that as well.

System.AggregateException: One or more errors occurred. ---> System.AggregateException: One or more errors occurred. ---> DotNetty.Transport.Channels.ClosedChannelException: I/O error occurred.
   --- End of inner exception stack trace ---
   --- End of inner exception stack trace ---
  at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in <f32579baafc1404fa37ba3ec1abdc0bd>:0 
  at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x0003e] in <f32579baafc1404fa37ba3ec1abdc0bd>:0 
  at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) [0x00028] in <f32579baafc1404fa37ba3ec1abdc0bd>:0 
  at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) [0x00008] in <f32579baafc1404fa37ba3ec1abdc0bd>:0 
  at System.Runtime.CompilerServices.ConfiguredTaskAwaitable+ConfiguredTaskAwaiter.GetResult () [0x00000] in <f32579baafc1404fa37ba3ec1abdc0bd>:0 
  at Microsoft.Azure.Devices.Client.Transport.Mqtt.Util+<WriteMessageAsync>d__14.MoveNext () [0x00072] in <ed298223c75a4d0da4cec9f5b71ac288>:0 
--- End of stack trace from previous location where exception was thrown ---
  at Microsoft.Azure.Devices.Client.Transport.TransportHandler+<>c__DisplayClass3_0.<HandleTimeoutCancellation>b__1 (System.Threading.Tasks.Task t) [0x00031] in <ed298223c75a4d0da4cec9f5b71ac288>:0 
  at System.Threading.Tasks.ContinuationTaskFromTask.InnerInvoke () [0x00024] in <f32579baafc1404fa37ba3ec1abdc0bd>:0 
  at System.Threading.Tasks.Task.Execute () [0x00010] in <f32579baafc1404fa37ba3ec1abdc0bd>:0 
--- End of stack trace from previous location where exception was thrown ---
  at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in <f32579baafc1404fa37ba3ec1abdc0bd>:0 
  at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x0003e] in <f32579baafc1404fa37ba3ec1abdc0bd>:0 
  at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) [0x00028] in <f32579baafc1404fa37ba3ec1abdc0bd>:0 
  at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) [0x00008] in <f32579baafc1404fa37ba3ec1abdc0bd>:0 
  at System.Runtime.CompilerServices.ConfiguredTaskAwaitable+ConfiguredTaskAwaiter.GetResult () [0x00000] in <f32579baafc1404fa37ba3ec1abdc0bd>:0 
  at Microsoft.Azure.Devices.Client.Transport.Mqtt.MqttTransportHandler+<OpenAsync>d__45.MoveNext () [0x00090] in <ed298223c75a4d0da4cec9f5b71ac288>:0 
--- End of stack trace from previous location where exception was thrown ---
  at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in <f32579baafc1404fa37ba3ec1abdc0bd>:0 
  at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x0003e] in <f32579baafc1404fa37ba3ec1abdc0bd>:0 
  at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) [0x00028] in <f32579baafc1404fa37ba3ec1abdc0bd>:0 
  at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) [0x00008] in <f32579baafc1404fa37ba3ec1abdc0bd>:0 
  at System.Runtime.CompilerServices.ConfiguredTaskAwaitable+ConfiguredTaskAwaiter.GetResult () [0x00000] in <f32579baafc1404fa37ba3ec1abdc0bd>:0 
  at Microsoft.Azure.Devices.Client.Transport.ProtocolRoutingDelegatingHandler+<TryOpenPrioritizedTransportsAsync>d__3.MoveNext () [0x00168] in <ed298223c75a4d0da4cec9f5b71ac288>:0 
--- End of stack trace from previous location where exception was thrown ---
  at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in <f32579baafc1404fa37ba3ec1abdc0bd>:0 
  at Microsoft.Azure.Devices.Client.Transport.ProtocolRoutingDelegatingHandler+<TryOpenPrioritizedTransportsAsync>d__3.MoveNext () [0x002e5] in <ed298223c75a4d0da4cec9f5b71ac288>:0 
--- End of stack trace from previous location where exception was thrown ---
  at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in <f32579baafc1404fa37ba3ec1abdc0bd>:0 
  at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x0003e] in <f32579baafc1404fa37ba3ec1abdc0bd>:0 
  at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) [0x00028] in <f32579baafc1404fa37ba3ec1abdc0bd>:0 
  at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) [0x00008] in <f32579baafc1404fa37ba3ec1abdc0bd>:0 
  at System.Runtime.CompilerServices.ConfiguredTaskAwaitable+ConfiguredTaskAwaiter.GetResult () [0x00000] in <f32579baafc1404fa37ba3ec1abdc0bd>:0 
  at Microsoft.Azure.Devices.Client.Transport.ProtocolRoutingDelegatingHandler+<OpenAsync>d__2.MoveNext () [0x00077] in <ed298223c75a4d0da4cec9f5b71ac288>:0 
--- End of stack trace from previous location where exception was thrown ---
  at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in <f32579baafc1404fa37ba3ec1abdc0bd>:0 
  at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x0003e] in <f32579baafc1404fa37ba3ec1abdc0bd>:0 
  at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) [0x00028] in <f32579baafc1404fa37ba3ec1abdc0bd>:0 
  at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) [0x00008] in <f32579baafc1404fa37ba3ec1abdc0bd>:0 
  at System.Runtime.CompilerServices.ConfiguredTaskAwaitable+ConfiguredTaskAwaiter.GetResult () [0x00000] in <f32579baafc1404fa37ba3ec1abdc0bd>:0 
  at Microsoft.Azure.Devices.Client.Transport.Mqtt.Util+<WriteMessageAsync>d__14.MoveNext () [0x00090] in <ed298223c75a4d0da4cec9f5b71ac288>:0 
--- End of stack trace from previous location where exception was thrown ---
  at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in <f32579baafc1404fa37ba3ec1abdc0bd>:0 
  at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x0003e] in <f32579baafc1404fa37ba3ec1abdc0bd>:0 
  at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) [0x00028] in <f32579baafc1404fa37ba3ec1abdc0bd>:0 
  at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) [0x00008] in <f32579baafc1404fa37ba3ec1abdc0bd>:0 
  at System.Runtime.CompilerServices.ConfiguredTaskAwaitable+ConfiguredTaskAwaiter.GetResult () [0x00000] in <f32579baafc1404fa37ba3ec1abdc0bd>:0 
  at Microsoft.Azure.Devices.Client.Transport.Mqtt.MqttIotHubAdapter+<Connect>d__32.MoveNext () [0x002bf] in <ed298223c75a4d0da4cec9f5b71ac288>:0 
--- End of stack trace from previous location where exception was thrown ---
  at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in <f32579baafc1404fa37ba3ec1abdc0bd>:0 
  at Microsoft.Azure.Devices.Client.Transport.ErrorDelegatingHandler+<ExecuteWithErrorHandlingAsync>d__20`1[T].MoveNext () [0x0031a] in <ed298223c75a4d0da4cec9f5b71ac288>:0 
--- End of stack trace from previous location where exception was thrown ---
  at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in <f32579baafc1404fa37ba3ec1abdc0bd>:0 
  at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x0003e] in <f32579baafc1404fa37ba3ec1abdc0bd>:0 
  at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) [0x00028] in <f32579baafc1404fa37ba3ec1abdc0bd>:0 
  at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) [0x00008] in <f32579baafc1404fa37ba3ec1abdc0bd>:0 
  at System.Runtime.CompilerServices.ConfiguredTaskAwaitable+ConfiguredTaskAwaiter.GetResult () [0x00000] in <f32579baafc1404fa37ba3ec1abdc0bd>:0 
  at Microsoft.Azure.Devices.Client.Transport.ErrorDelegatingHandler+<OpenAsync>d__4.MoveNext () [0x0019c] in <ed298223c75a4d0da4cec9f5b71ac288>:0 
--- End of stack trace from previous location where exception was thrown ---
  at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in <f32579baafc1404fa37ba3ec1abdc0bd>:0 
  at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x0003e] in <f32579baafc1404fa37ba3ec1abdc0bd>:0 
  at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) [0x00028] in <f32579baafc1404fa37ba3ec1abdc0bd>:0 
  at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) [0x00008] in <f32579baafc1404fa37ba3ec1abdc0bd>:0 
  at System.Runtime.CompilerServices.ConfiguredTaskAwaitable+ConfiguredTaskAwaiter.GetResult () [0x00000] in <f32579baafc1404fa37ba3ec1abdc0bd>:0 
  at Microsoft.Azure.Devices.Client.Transport.RetryDelegatingHandler+<OpenAsync>d__23.MoveNext () [0x000b1] in <ed298223c75a4d0da4cec9f5b71ac288>:0 
--- End of stack trace from previous location where exception was thrown ---
  at Microsoft.Azure.Devices.Client.DeviceClient+<>c.<ApplyTimeout>b__74_2 (System.Threading.Tasks.Task t) [0x00013] in <ed298223c75a4d0da4cec9f5b71ac288>:0 
  at System.Threading.Tasks.ContinuationTaskFromTask.InnerInvoke () [0x00024] in <f32579baafc1404fa37ba3ec1abdc0bd>:0 
  at System.Threading.Tasks.Task.Execute () [0x00010] in <f32579baafc1404fa37ba3ec1abdc0bd>:0 
--- End of stack trace from previous location where exception was thrown ---
  at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in <f32579baafc1404fa37ba3ec1abdc0bd>:0 
  at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x0003e] in <f32579baafc1404fa37ba3ec1abdc0bd>:0 
  at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) [0x00028] in <f32579baafc1404fa37ba3ec1abdc0bd>:0 
  at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) [0x00008] in <f32579baafc1404fa37ba3ec1abdc0bd>:0 
  at System.Runtime.CompilerServices.ConfiguredTaskAwaitable+ConfiguredTaskAwaiter.GetResult () [0x00000] in <f32579baafc1404fa37ba3ec1abdc0bd>:0 
  at SceneSkopeKiosk.Iot.IotConnection+<CreateDeviceClientAsync>d__11.MoveNext () [0x000a9] in C:\Users\nick\Source\Repos\SceneSkopeKiosk\SceneSkopeKiosk.Iot\IotConnection.cs:59 
--- End of stack trace from previous location where exception was thrown ---
  at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in <f32579baafc1404fa37ba3ec1abdc0bd>:0 
  at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x0003e] in <f32579baafc1404fa37ba3ec1abdc0bd>:0 
  at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) [0x00028] in <f32579baafc1404fa37ba3ec1abdc0bd>:0 
  at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) [0x00008] in <f32579baafc1404fa37ba3ec1abdc0bd>:0 
  at System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1+ConfiguredTaskAwaiter[TResult].GetResult () [0x00000] in <f32579baafc1404fa37ba3ec1abdc0bd>:0 
  at SceneSkopeKiosk.Iot.IotConnection+<SendString>d__26.MoveNext () [0x0004f] in C:\Users\nick\Source\Repos\SceneSkopeKiosk\SceneSkopeKiosk.Iot\IotConnection.cs:102 
--- End of stack trace from previous location where exception was thrown ---
  at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in <f32579baafc1404fa37ba3ec1abdc0bd>:0 
  at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x0003e] in <f32579baafc1404fa37ba3ec1abdc0bd>:0 
  at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) [0x00028] in <f32579baafc1404fa37ba3ec1abdc0bd>:0 
  at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) [0x00008] in <f32579baafc1404fa37ba3ec1abdc0bd>:0 
  at System.Runtime.CompilerServices.ConfiguredTaskAwaitable+ConfiguredTaskAwaiter.GetResult () [0x00000] in <f32579baafc1404fa37ba3ec1abdc0bd>:0 
  at SceneSkopeKiosk.Services.IotService+<SendNotificationAsync>d__40.MoveNext () [0x00177] in C:\Users\nick\Source\Repos\SceneSkopeKiosk\SceneSkopeKiosk\Services\IotService.cs:192 
---> (Inner Exception #0) System.AggregateException: One or more errors occurred. ---> DotNetty.Transport.Channels.ClosedChannelException: I/O error occurred.
   --- End of inner exception stack trace ---
---> (Inner Exception #0) DotNetty.Transport.Channels.ClosedChannelException: I/O error occurred.<---
<---
RubiaL commented 5 years ago

Thanks for the feedback.This is currently in our backlog and will consider it as part of our planning cycle

az-iot-builder-01 commented 5 years ago

@FinitelyFailed, @acambitsis, @CIPop, @davidmaiden, @nrandell, @RubiaL, thank you for your contribution to our open-sourced project! Please help us improve by filling out this 2-minute customer satisfaction survey

kensykora commented 4 years ago

This is also not working under iOS. Same behavior as the original issue -- ReceiveAsync() never returns any messages, and Sends also throw a TimeoutException .

vinagesh commented 3 years ago

This issue is really old and seems to be working with the latest SDK and Visual Studio version. We also don't support Xamarin officially yet but if there are any other issues, please feel free to open a new one.

abhipsaMisra commented 3 years ago

Re-opening and closing to work around dashboard issue.

abhipsaMisra commented 3 years ago

Closing the issue.