question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[BUG] FormsRecognizer/ FieldValue.AsTime fails because the json does not contain valueTime

See original GitHub issue

Describe the bug Attempting to do AsTime on a time field fails with

Field value is null.

Expected behavior AsTime should return the TimeSpan if it was parsed successfully.

Actual behavior (include Exception or Stack Trace) The StartRecognizeCustomForms returns json which contains:

                  "time": {
                    "type": "time",
                    "text": "23:55",
                    "page": 1,
                    "boundingBox": [2.95, 6.095, 3.22, 6.095, 3.22, 6.175, 2.95, 6.175],
                    "elements": ["#/readResults/0/lines/46/words/0"]
                  }

Note that there is no valueTime which appear to be what FieldValue_internal.DeserializeFieldValue_internal looks for:

                if (property.NameEquals("valueTime"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    valueTime = property.Value.GetTimeSpan("T");
                    continue;
                }

Hence it throws in

 	Azure.AI.FormRecognizer.dll!Azure.AI.FormRecognizer.Models.FieldValue.AsTime`

as the valueTime field is not set.

To Reproduce Steps to reproduce the behavior (include a code snippet, screenshot, or any additional information that might help us reproduce the issue)

  1. Anaylse a form with a Time tag using c#
            var forms = recognizerClient
                .StartRecognizeCustomForms("modelIdHere", fs, new RecognizeCustomFormsOptions
                {
                    
                })
                .WaitForCompletionAsync();
  1. Find the field and do AsTime(), in my case this is in a table so I have
            var fieldName = portCallIx == 0 ? "load" : "discharge";
            if (Form.Fields.ContainsKey(fieldName))
            {
                var list = Form.Fields[fieldName].Value.AsList();
                var arrivedRow = list.FirstOrDefault(lv => lv.Value.AsDictionary()["event"].Value.AsString().StartsWith("Arrived", true, CultureInfo.InvariantCulture));
                if (arrivedRow != null)
                {
                    var dict = arrivedRow.Value.AsDictionary();
                    var ts = dict["time"].Value.AsTime();
                    return dict["date"].Value.AsDate().SetTime(ts.Hours, ts.Minutes);
                }
            }

Environment:

  • Name and version of the Library package used: Azure.AI.FormRecognizer 3.1.0-beta.4
  • WIndows 10 .net framework 4.7.2 Microsoft Visual Studio Professional 2015 Version 14.0.25431.01 Update 3 Microsoft .NET Framework Version 4.8.04084

Installed Version: Professional

LightSwitch for Visual Studio 2015 00322-40000-00000-AA879 Microsoft LightSwitch for Visual Studio 2015

Microsoft Visual Studio Tools for Applications 2015 00322-40000-00000-AA879 Microsoft Visual Studio Tools for Applications 2015

Visual Basic 2015 00322-40000-00000-AA879 Microsoft Visual Basic 2015

Visual C# 2015 00322-40000-00000-AA879 Microsoft Visual C# 2015

Visual C++ 2015 00322-40000-00000-AA879 Microsoft Visual C++ 2015

Application Insights Tools for Visual Studio Package 7.0.20622.1 Application Insights Tools for Visual Studio

ASP.NET and Web Tools 2015.1 (Beta8) 14.1.11107.0 ASP.NET and Web Tools 2015.1 (Beta8)

ASP.NET Web Frameworks and Tools 2012.2 4.1.41102.0 For additional information, visit http://go.microsoft.com/fwlink/?LinkID=309563

ASP.NET Web Frameworks and Tools 2013 5.2.40314.0 For additional information, visit http://www.asp.net/

Common Azure Tools 1.8 Provides common services for use by Azure Mobile Services and Microsoft Azure Tools.

JavaScript Language Service 2.0 JavaScript Language Service

JavaScript Project System 2.0 JavaScript Project System

JetBrains ReSharper 2020.3.4 Build 203.0.20210316.132251 JetBrains ReSharper package for Microsoft Visual Studio. For more information about ReSharper, visit http://www.jetbrains.com/resharper. Copyright © 2021 JetBrains, Inc.

Microsoft Azure Mobile Services Tools 1.4 Microsoft Azure Mobile Services Tools

NuGet Package Manager 3.6.0 NuGet Package Manager in Visual Studio. For more information about NuGet, visit http://docs.nuget.org/.

PreEmptive Analytics Visualizer 1.2 Microsoft Visual Studio extension to visualize aggregated summaries from the PreEmptive Analytics product.

SQL Server Data Tools 14.0.60519.0 Microsoft SQL Server Data Tools

TypeScript 1.8.36.0 TypeScript tools for Visual Studio

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:13 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
maririoscommented, Oct 4, 2021

@yowl you could pin and constantly check the service What's new page to learn when this feature is going to be included: https://docs.microsoft.com/azure/applied-ai-services/form-recognizer/whats-new?tabs=csharp

1reaction
maririoscommented, Apr 14, 2021

After following up with the service team, Custom Forms currently doesn’t support valueTime and will always return the value on the text property. They are going to add this functionality soon although I don’t have a specific date yet. We will update this issue when the change happens.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Could not build the model: Cannot use fields.json; All ...
Form Recognizer Studio error ModelBuildError: Could not build the model: Cannot use fields.json; All labels are processed as normal key-value ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found