[BUG] AI.FormRecognizer SDK not parsing date correctly
See original GitHub issueDescribe the bug Even though the form recognizer service is returning the correct date from a form, the SDK is failing at parsing it.
Expected behavior
I expect the DateTime
to be parsed in the right format, or at least to have some control over the locale which should be used for parsing.
Actual behavior (include Exception or Stack Trace)
The ValueData
property holds the string with the correct datetime value (nl-NL locale format), but the operation FormField.Value.AsDate()
returns the error from line https://github.com/Azure/azure-sdk-for-net/blob/b752803792ebaddad5a4de009857b51f7c3f0399/sdk/formrecognizer/Azure.AI.FormRecognizer/src/FieldValue.cs#L266. This indicates the string value was not correctly parsed to a valid DateTime
object.
Example:
This perfectly valid date will throw the above error when trying to retrieve it using AsDate()
.
To Reproduce Steps to reproduce the behavior (include a code snippet, screenshot, or any additional information that might help us reproduce the issue)
- Recognize a document in another locale than en-US
- Try to exact a
DateTime
field as mentioned
Environment:
- Azure.AI.FormRecognizer
- Windows 10, .NET SDK 5.0.201, Host version 5.0.4
- Visual Studio 16.9.2
Issue Analytics
- State:
- Created 2 years ago
- Comments:14 (6 by maintainers)
Top GitHub Comments
@kinelski Thanks, I confirm that works for me.
DocumentFieldValue.AsDate
does not try to parse the content string. If you get an exception when you invoke it, it means that the service could not parse the date and hasn’t returned a value to the SDK. In 4.0.0, when this happens,DocumentField.FieldType
will be set toDocumentFieldType.Unknown
, so you don’t need to rely on exceptions:To reproduce this behavior with the model factory, you can call the
DocumentFieldValueWithUnknownFieldType
method:Please let me know if this solves your problem.