Guest User

Guest User

  • Tech Writer
  • 2.1k
  • 480.6k

DeviceNotFoundException

Sep 13 2019 5:34 AM
Hi Team
 
I am running backend application on this module(C#), both on my CMD to check if it connect to my IOT hub, im getting a device not connection exception is being not found.
 
On my IOT hub i have device called "MyDotnetDevice, but if i use DeviceExolore to test for connecting to my IOT, it sends the message well and can view it on the portal as well on Azure. The code is as follows, but the question is why am i getting this exception both my CMD and VS IDE;
 
C:\Users\Gcobanim\source\repos\azure-iot-samples-csharp-master\azure-iot-samples-csharp-master\iot-hub\Quickstarts\back-end-application>dotnet run
IoT Hub Quickstarts #2 - Back-end application.
Unhandled Exception: Microsoft.Azure.Devices.Common.Exceptions.DeviceNotFoundException: Device {"Message":"{\"errorCode\":404103,\"trackingId\":\"3a490c8ca97b4ea88a6965bc61d5af5a-G:0-TimeStamp:09/13/2019 10:27:36-G:4-TimeStamp:09/13/2019 10:27:36\",\"message\":\"Timed out waiting for device to subscribe.\",\"info\":{},\"timestampUtc\":\"2019-09-13T10:27:36.06523Z\"}","ExceptionMessage":""} not registered
at Microsoft.Azure.Devices.HttpClientHelper.ExecuteAsync(HttpClient httpClient, HttpMethod httpMethod, Uri requestUri, Func`3 modifyRequestMessageAsync, Func`2 isMappedToException, Func`3 processResponseMessageAsync, IDictionary`2 errorMappingOverrides, CancellationToken cancellationToken)
at Microsoft.Azure.Devices.HttpClientHelper.PostAsync[T,T2](Uri requestUri, T entity, TimeSpan operationTimeout, IDictionary`2 errorMappingOverrides, IDictionary`2 customHeaders, CancellationToken cancellationToken)
at back_end_application.BackEndApplication.InvokeMethod() in C:\Users\Gcobanim\source\repos\azure-iot-samples-csharp-master\azure-iot-samples-csharp-master\iot-hub\Quickstarts\back-end-application\BackEndApplication.cs:line 27
at back_end_application.BackEndApplication.Main(String[] args) in C:\Users\Gcobanim\source\repos\azure-iot-samples-csharp-master\azure-iot-samples-csharp-master\iot-hub\Quickstarts\back-end-application\BackEndApplication.cs:line 39
 
C# code
  1. using System;  
  2. using System.Collections.Generic;  
  3. using System.Linq;  
  4. using System.Text;  
  5. using System.Threading.Tasks;  
  6. using Microsoft.Azure.Devices.Client;  
  7. using Microsoft.Azure.Devices;  
  8. using Microsoft.Azure.Devices.Common.Exceptions;  
  9. namespace BackEndApplication  
  10. {  
  11. class Program  
  12. {  
  13. private static ServiceClient s_serviceClient;  
  14. private readonly static string s_connectionString = "HostName=UniversityIOTHub.azure-devices.net;SharedAccessKeyName=service;SharedAccessKey=r***=";  
  15. private static async Task InvokeMethod()  
  16. {  
  17. var methodInvocation = new CloudToDeviceMethod("SetTelemetryInterval") { ResponseTimeout = TimeSpan.FromSeconds(30) };  
  18. methodInvocation.SetPayloadJson("10");  
  19. var response = await s_serviceClient.InvokeDeviceMethodAsync("MyDotnetDevice", methodInvocation);  
  20. Console.WriteLine("Response status:{0}, payload", response.Status);  
  21. Console.WriteLine(response.GetPayloadAsJson());  
  22. }  
  23. static void Main(string[] args)  
  24. {  
  25. Console.WriteLine("IOT Hub Test-- BackEndApplication.\n");  
  26. s_serviceClient = ServiceClient.CreateFromConnectionString(s_connectionString);  
  27. InvokeMethod().GetAwaiter().GetResult();  
  28. Console.WriteLine("Press Enter to exit.");  
  29. Console.ReadLine();  
  30. }  
  31. }  
  32. }  

Answers (5)