botbuilder-dotnet: Not able to parse DateTimeSpec value "the hour" while reading response from luis in bot app

Ask

May I know why “the hour” text could not be converted in DateTimeSpec type? Do I need to tweak something from my c# model side to allow it?

Package

<PackageReference Include="Microsoft.Bot.Builder.AI.Luis" Version="4.12.0" />

Luis response JSON

{
  "useralias": [
    "abcd"
  ],
  "number": [
    2
  ],
  "datetime": [
    {
      "timex": [
        "(T14, T15,PT1H)"
      ],
      "type": "timerange"
    },
    "the hour"
  ],
  "personName": [
    "Tony"
  ],
  "$instance": {
    "useralias": [
      {
        "type": "useralias",
        "text": "abcd",
        "startIndex": 0,
        "endIndex": 10,
        "modelType": "Entity Extractor",
        "recognitionSources": [
          "model"
        ]
      }
    ],
    "number": [
      {
        "type": "builtin.number",
        "text": "2",
        "startIndex": 31,
        "endIndex": 32,
        "modelType": "Prebuilt Entity Extractor",
        "recognitionSources": [
          "model"
        ]
      }
    ],
    "datetime": [
      {
        "type": "builtin.datetimeV2.timerange",
        "text": "2 to 3pm",
        "startIndex": 31,
        "endIndex": 39,
        "modelType": "Prebuilt Entity Extractor",
        "recognitionSources": [
          "model"
        ]
      },
      {
        "type": "builtin.datetimeV2.duration",
        "text": "the hour",
        "startIndex": 99,
        "endIndex": 107,
        "modelType": "Prebuilt Entity Extractor",
        "recognitionSources": [
          "model"
        ]
      }
    ],
    "personName": [
      {
        "type": "builtin.personName",
        "text": "Tony",
        "startIndex": 59,
        "endIndex": 65,
        "modelType": "Prebuilt Entity Extractor",
        "recognitionSources": [
          "model"
        ]
      }
    ]
  }
}

Error

{"Error converting value \"the hour\" to type 'Microsoft.Bot.Builder.AI.Luis.DateTimeSpec'. Path 'entities.datetime[1]', line 1, position 362."}

   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.EnsureType(JsonReader reader, Object value, CultureInfo culture, JsonContract contract, Type targetType)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.PopulateList(IList list, JsonReader reader, JsonArrayContract contract, JsonProperty containerProperty, String id)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateList(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, Object existingValue, String id)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.SetPropertyValue(JsonProperty property, JsonConverter propertyConverter, JsonContainerContract containerContract, JsonProperty containerProperty, JsonReader reader, Object target)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.PopulateObject(Object newObject, JsonReader reader, JsonObjectContract contract, JsonProperty member, String id)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateObject(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.SetPropertyValue(JsonProperty property, JsonConverter propertyConverter, JsonContainerContract containerContract, JsonProperty containerProperty, JsonReader reader, Object target)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.PopulateObject(Object newObject, JsonReader reader, JsonObjectContract contract, JsonProperty member, String id)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateObject(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize(JsonReader reader, Type objectType, Boolean checkAdditionalContent)
   at Newtonsoft.Json.JsonSerializer.DeserializeInternal(JsonReader reader, Type objectType)
   at Newtonsoft.Json.JsonSerializer.Deserialize(JsonReader reader, Type objectType)
   at Newtonsoft.Json.JsonConvert.DeserializeObject(String value, Type type, JsonSerializerSettings settings)
   at Newtonsoft.Json.JsonConvert.DeserializeObject[T](String value, JsonSerializerSettings settings)
   at Newtonsoft.Json.JsonConvert.DeserializeObject[T](String value)
   at Luis.GeneralLuis.Convert(Object result) 
   at Microsoft.Bot.Builder.AI.Luis.LuisRecognizer.<RecognizeAsync>d__26`1.MoveNext()
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
   at OOFAssistant.Controllers.NotifyController.<PullAliasRecord>d__17.MoveNext() 
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
   at OOFAssistant.Controllers.NotifyController.<BotCallback>d__15.MoveNext() 

Inner exception

Could not cast or convert from System.String to Microsoft.Bot.Builder.AI.Luis.DateTimeSpec.

   at Newtonsoft.Json.Utilities.ConvertUtils.EnsureTypeAssignable(Object value, Type initialType, Type targetType)
   at Newtonsoft.Json.Utilities.ConvertUtils.ConvertOrCast(Object initialValue, CultureInfo culture, Type targetType)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.EnsureType(JsonReader reader, Object value, CultureInfo culture, JsonContract contract, Type targetType)

Convert logic

        public void Convert(dynamic result)
        {
            var app = JsonConvert.DeserializeObject<GeneralLuis>(
                JsonConvert.SerializeObject(
                    result,
                    new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore, Error = OnError }
                )
            );

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 17 (5 by maintainers)

Most upvoted comments

This issue is solved in the new version of Recognizers. We are updating the .NET SDK to use these packages in PR #5992.

Thanks Dana for the update. The recognizers-text team has released new packages, and we are indeed waiting for LUIS (and the C# SDK) to pickup the latest packages. The SDK is planning to take these in R14, with @EricDahlvang having looked at them.