Azure / azure-iot-sdk-csharp

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

[Bug Report] Querying jobs from some IoT Hubs returns an unexpected ArgumentException #3352

Closed matthewshan closed 11 months ago

matthewshan commented 1 year ago

Context

Description of the issue

When attempting to query a list of jobs from one of our IoT Hubs, I get "Requested value 'unknown' was not found." I see this error for some IoT Hubs, whereas others do not. After hours of debugging, I cannot identify the differentiating factors. One s1 iot hub allows for this code, and a different s1 and one free tier iot hub produces this error.

I double-checked to see that all my jobs have the status of completed and the type of scheduleUpdateTwin on all of these hubs

Code sample exhibiting the issue

public async Task<List<JobResponse>> GetActiveJobs(string connectionString)
    {
        var jobClient = JobClient.CreateFromConnectionString(connectionString);
        var query = jobClient.CreateQuery(jobType: JobType.ScheduleUpdateTwin, jobStatus: JobStatus.Running);

        var activeJobs = new List<JobResponse>();
        while (query.HasMoreResults)
        {
            var result = await query.GetNextAsJobResponseAsync(); // <-- Error is thrown on this line
            if (result != null)
            {
                activeJobs.AddRange(result);
            }
        }

        await jobClient.CloseAsync();

        return activeJobs;
    }

Console log of the issue

System.ArgumentException: Requested value 'unknown' was not found.
   at System.Enum.TryParseByName(RuntimeType enumType, ReadOnlySpan`1 value, Boolean ignoreCase, Boolean throwOnFailure, UInt64& result)
   at System.Enum.TryParseInt32Enum(RuntimeType enumType, ReadOnlySpan`1 value, Int32 minInclusive, Int32 maxInclusive, Boolean ignoreCase, Boolean throwOnFailure, TypeCode type, Int32& result)
   at System.Enum.TryParse(Type enumType, ReadOnlySpan`1 value, Boolean ignoreCase, Boolean throwOnFailure, Object& result)
   at System.Enum.Parse(Type enumType, String value)
   at Microsoft.Azure.Devices.QueryResult.FromHttpResponseAsync(HttpResponseMessage response)
   at Microsoft.Azure.Devices.JobClient.GetJobsAsync(Nullable`1 jobType, Nullable`1 jobStatus, Nullable`1 pageSize, String continuationToken, CancellationToken cancellationToken)
   at Microsoft.Azure.Devices.Query.GetNextAsync(QueryOptions options)
   at Microsoft.Azure.Devices.Query.GetAndCastNextResultAsync[T](QueryResultType type, QueryOptions options)
   at Microsoft.Azure.Devices.Query.GetNextAsJobResponseAsync(QueryOptions options)
   at Microsoft.Azure.Devices.Query.GetNextAsJobResponseAsync()
   at TestProject.Libraries.IotJobsHelper.GetJobs(String connectionString) in IotJobsHelper.cs:line 40
   at Program.<Main>$(String[] args) in Program.cs:line 8
### Tasks
matthewshan commented 1 year ago

Bump

timtay-microsoft commented 1 year ago

The service side of this has changed lately, and it's possible that this bug is because of that. I'll follow up with the service engineers to see if something was broken here.

timtay-microsoft commented 11 months ago

Service side engineers have confirmed that this is a bug that they are working to fix. You should get this fix as soon as the service team deploys it. Since this isn't an SDK-side bug, I'll go ahead and close this thread.

matthewshan commented 9 months ago

@timtay-microsoft Thanks for the update! I'm unfortunately still seeing this as an issue. Is there a ticket on their end we can use to track this issue, or any news feeds I should pay attention to?

timtay-microsoft commented 9 months ago

If you open a ticket through the Azure portal, you should be able to getter a better picture of when the service team will have this fix rolled out to your hub. We don't really track service-side updates in this or any other SDK repo, unfortunately.