Comments (6)
Based on investigation, the code creates the first chain of inner handlers correctly and sets the callback. However, within the call of SetDesiredPropretyUpdateCallback(), the code resets part of the chain without setting the callback again - so it gets lost.
We did a work around where we checked if the inner handler is present before creating a new one. This unblocked us.
from azure-iot-sdk-csharp.
Jasmine pointed me to the sample, and the problem is that I’m missing the explicit call to OpenAsync()
Client = DeviceClient.CreateFromConnectionString(DeviceConnectionString, TransportType.Mqtt);
Client.OpenAsync().Wait(); // <-- this is missing in my repro.
Client.SetDesiredPropertyUpdateCallback(OnDesiredPropertyChanged, null).Wait();
Once I added this, things started to work.
This makes sense, because when I debugged SetDesiredPropertyUpdateCallback(), it ended-up calling OpenAsync(), and during that call the callback was lost. In other words, the code path for OpenAsync() does not expect the callbacks to be set, and overwrites them.
So, if SetDesiredPropertyUpdateCallback() is expected to handle the case where OpenAsync() hasn't been called yet - we might still have a bug.
from azure-iot-sdk-csharp.
The is a valid bug and SetDesiredPropertyUpdateCallback() is expected to handle the case where OpenAsync() hasn't been called. Fix is on the way. Thanks.
from azure-iot-sdk-csharp.
commit: ccd8bc9
from azure-iot-sdk-csharp.
I'm trying to run the sample (https://github.com/Azure/azure-iot-sdk-csharp/blob/master/device/samples/DeviceClientTwinMqttSample/Program.cs), but it crashes on:
Client.SetDesiredPropertyUpdateCallback(OnDesiredPropertyChanged, null).Wait();
Connecting to hub
Error in sample: System.NullReferenceException: Object reference not set to an instance of an object.
at Microsoft.Azure.Devices.Client.Transport.TransportHandlerFactory.Create(IPipelineContext context)
at Microsoft.Azure.Devices.Client.DeviceClient.<>c__DisplayClass24_0.b__4(IPipelineContext ctx)
at Microsoft.Azure.Devices.Client.Transport.DefaultDelegatingHandler.EnsureInnerHandlerInitialized()
at Microsoft.Azure.Devices.Client.Transport.DefaultDelegatingHandler.get_InnerHandler()
at Microsoft.Azure.Devices.Client.Transport.DefaultDelegatingHandler.set_TwinUpdateHandler(TwinUpdateCallback value)
at Microsoft.Azure.Devices.Client.Transport.DefaultDelegatingHandler.set_TwinUpdateHandler(TwinUpdateCallback value)
at Microsoft.Azure.Devices.Client.Transport.DefaultDelegatingHandler.set_TwinUpdateHandler(TwinUpdateCallback value)
at Microsoft.Azure.Devices.Client.Transport.DefaultDelegatingHandler.set_TwinUpdateHandler(TwinUpdateCallback value)
at Microsoft.Azure.Devices.Client.DeviceClient.<>c__DisplayClass60_0.<b__0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.Azure.Devices.Client.TaskHelpers.d__17.MoveNext()
The only modification I did to the code was to set the connection string for my device on the form:
"HostName=<iothub_host_name>;DeviceId=<device_id>;SharedAccessKey=<device_key>"
using my real connection string for the device of course.
I'm using v1.2.2 of the Microsoft.Azure.Devices.Client
from azure-iot-sdk-csharp.
Fix provided in 1.2.3. Please let us know if still having issue.
from azure-iot-sdk-csharp.
Related Issues (20)
- [Technical Question] Security: Check root certificate on device-to-cloud connection HOT 10
- Unhandled exception. Microsoft.Azure.Devices.Client.Exceptions.IotHubException: Request 817bda7c-6fc4-40e0-8946-93eb851fcb12 returned status 403 [Bug Report] HOT 7
- [Bug Report] Send message in batch to multiple outputs using ModuleClient throws HOT 2
- Is it possible to send bulk messages in telemetry from device to IoT hub? [Technical Question]
- [Technical Question] HttpClientHelper error code 400030 HOT 3
- [Bug Report] When try to fetch reported properties after updating the reported property it will return previous version of reported property not the latest one. HOT 2
- [QUERY] How to properly acknowledge IoT hub messages HOT 6
- [feature request] Make DPS Queries testable HOT 2
- MQTT Channel is Closed / Migrating Sample to .net8 caused an issue HOT 5
- DeviceNotFoundException results in InvalidErrorCode (404103) HOT 2
- [Bug Report] v2.0.0 now removed from nuget package HOT 4
- Getting PlatformNotSupportedException on .NET Framework 4.6.1 HOT 3
- [Technical Question] HOT 1
- [Bug Report] HOT 2
- [Bug Report]Edgehub - Unknown feedback message - HOT 3
- Getting Connection Closed on New Connection Error when it was previously not generated HOT 2
- [Technical Question] Device Update for IoT Hub support HOT 1
- [Bug Report]DeviceClient.GetFileUploadSaSUriAsync() returns invalid SAS when hub is using System-identity. HOT 1
- Device Client Reconnects After Extended 'Disconnected_Retrying' State Without Entering 'Retry_Expired' as Documented HOT 1
- [Bug Report] SendEventAsync() hangs forever when the DeviceClient is Closed/Disposed while ConnectionStateChangedHandler is running
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from azure-iot-sdk-csharp.