Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Newtonsoft.Json.JsonReaderException - Unexpected character encountered while parsing value when trying to utilize #1257

Open
MCKRUZ opened this issue Jun 29, 2021 · 5 comments
Assignees
Labels
backlog The issue is out of scope for the current iteration but it will be evaluated in a future release. Bot Services Required for internal Azure reporting. Do not delete. Do not change color. bug Indicates an unexpected problem or an unintended behavior. customer-replied-to Indicates that the team has replied to the issue reported by the customer. Do not delete. customer-reported Issue is created by anyone that is not a collaborator in the repository. needs-triage The issue has just been created and it has not been reviewed by the team. P1 Painful if we don't fix, won't block releasing
Milestone

Comments

@MCKRUZ
Copy link

MCKRUZ commented Jun 29, 2021

Versions

I'm using version 4.13.3 of the CLI
Version "luis_schema_version": "7.0.0", of the schema.

Describe the bug

I exported out the attached
PS-CustomerService-Test.txt
json file into a new class and then ran this code.

var recognizerResult = await _botServices.Dispatch.RecognizeAsync<LuisModel>(stepContext.Context, cancellationToken);

Where _botServices.Dispatch is of type LuisRecognizer

It's failing in this piece of code

var app = JsonConvert.DeserializeObject<LuisModel>(
    JsonConvert.SerializeObject(
        result,
        new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore, Error = OnError }
    )
);

This is the error log

Newtonsoft.Json.JsonReaderException
HResult=0x80131500
Message=Unexpected character encountered while parsing value: [. Path 'entities.BugReport_ML[0].Description[0].Bug', line 1, position 390.
Source=Newtonsoft.Json
StackTrace:
at Newtonsoft.Json.JsonTextReader.ReadStringValue(ReadType readType)
at Newtonsoft.Json.JsonTextReader.ReadAsString()
at Newtonsoft.Json.JsonReader.ReadForType(JsonContract contract, Boolean hasConverter)
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.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.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 System.Dynamic.UpdateDelegates.UpdateAndExecute2[T0,T1,TRet](CallSite site, T0 arg0, T1 arg1)
at Luis.LUISModel.Convert(Object result) in C:\Users\kruz7\Desktop\Demo5\Demo\Demo\After\PluralsightBot\PluralsightBot\Models\LUISModel.cs:line 94
at Microsoft.Bot.Builder.AI.Luis.LuisRecognizer.d__27`1.MoveNext()

This exception was originally thrown at this call stack:
[External Code]
Luis.LUISModel.Convert(dynamic) in LUISModel.cs
[External Code]

@MCKRUZ MCKRUZ added bug Indicates an unexpected problem or an unintended behavior. needs-triage The issue has just been created and it has not been reviewed by the team. labels Jun 29, 2021
@stevengum stevengum added customer-reported Issue is created by anyone that is not a collaborator in the repository. Bot Services Required for internal Azure reporting. Do not delete. Do not change color. labels Jun 30, 2021
@munozemilio munozemilio assigned tsuwandy and unassigned munozemilio Jun 30, 2021
@tsuwandy
Copy link
Contributor

@MCKRUZ, could you clarify? You used bf luis to esport a LUIS app? The bot runs against a LUIS Dispatch app, correct? This error is run time error.

@MCKRUZ
Copy link
Author

MCKRUZ commented Jun 30, 2021

I exported out the LUIS XML using the LUIS gui then created the class using the BF CLI code generator, yes it runs against a dispatch app that is correct. And yes it's a runtime error also correct.

@munozemilio munozemilio assigned axelsrz and unassigned tsuwandy Jul 1, 2021
@MCKRUZ
Copy link
Author

MCKRUZ commented Jul 2, 2021

So I figured out the issue as to the "why" it's failing..

// <auto-generated>
// Code generated by luis:generate:cs
// Tool github: https://github.com/microsoft/botframework-cli
// Changes may cause incorrect behavior and will be lost if the code is
// regenerated.
// </auto-generated>
using Newtonsoft.Json;
using Newtonsoft.Json.Serialization;
using System;
using System.Collections.Generic;
using Microsoft.Bot.Builder;
using Microsoft.Bot.Builder.AI.Luis;
namespace Luis
{
    public partial class LuisModel : IRecognizerConvert
    {
        [JsonProperty("text")]
        public string Text;

        [JsonProperty("alteredText")]
        public string AlteredText;

        public enum Intent
        {
            GreetingIntent,
            NewBugReportIntent,
            None,
            QueryBugTypeIntent
        };
        [JsonProperty("intents")]
        public Dictionary<Intent, IntentScore> Intents;

        public class _Entities
        {
            // Built-in entities
            public DateTimeSpec[] datetime;
            public string[] phonenumber;

            // Lists
            public string[][] BugTypes_List;


            // Composites
            public class _InstanceDescription
            {
                public InstanceData[] Bug;
            }
            public class DescriptionClass
            {
                public string[] Bug;
                [JsonProperty("$instance")]
                public _InstanceDescription _instance;
            }
            public DescriptionClass[] Description;

            public class _InstanceBugReport_ML
            {
                public InstanceData[] CallbackTime;
                public InstanceData[] PhoneNumber;
                public InstanceData[] Description;
            }
            public class BugReport_MLClass
            {
                public string[] CallbackTime;
                public string[] PhoneNumber;
                public DescriptionClass[] Description;
                [JsonProperty("$instance")]
                public _InstanceBugReport_ML _instance;
            }
            public BugReport_MLClass[] BugReport_ML;

            // Instance
            public class _Instance
            {
                public InstanceData[] Bug;
                public InstanceData[] BugReport_ML;
                public InstanceData[] BugTypes_List;
                public InstanceData[] CallbackTime;
                public InstanceData[] Description;
                public InstanceData[] PhoneNumber;
                public InstanceData[] datetime;
                public InstanceData[] phonenumber;
            }
            [JsonProperty("$instance")]
            public _Instance _instance;
        }
        [JsonProperty("entities")]
        public _Entities Entities;

        [JsonExtensionData(ReadData = true, WriteData = true)]
        public IDictionary<string, object> Properties { get; set; }

        public void Convert(dynamic result)
        {
            var app = JsonConvert.DeserializeObject<LuisModel>(
                JsonConvert.SerializeObject(
                    result,
                    new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore, Error = OnError }
                )
            );
            Text = app.Text;
            AlteredText = app.AlteredText;
            Intents = app.Intents;
            Entities = app.Entities;
            Properties = app.Properties;
        }

        private static void OnError(object sender, ErrorEventArgs args)
        {
            // If needed, put your custom error logic here
            Console.WriteLine(args.ErrorContext.Error.Message);
            args.ErrorContext.Handled = true;
        }

        public (Intent intent, double score) TopIntent()
        {
            Intent maxIntent = Intent.None;
            var max = 0.0;
            foreach (var entry in Intents)
            {
                if (entry.Value.Score > max)
                {
                    maxIntent = entry.Key;
                    max = entry.Value.Score.Value;
                }
            }
            return (maxIntent, max);
        }
    }
}

The Description Class above should read

 public string[][] Bug;

instead of

 public string[] Bug;

Then it's all unicorns and rainbows. Not sure how this translates in the code generator but hopefully this helps.

@axelsrz
Copy link
Member

axelsrz commented Jul 7, 2021

Hello @MCKRUZ thanks for submitting this. We will provide a fix in our next milestone R15. Thanks

@axelsrz axelsrz added the customer-replied-to Indicates that the team has replied to the issue reported by the customer. Do not delete. label Jul 7, 2021
@axelsrz axelsrz added this to the R15 milestone Jul 7, 2021
@munozemilio munozemilio added the P1 Painful if we don't fix, won't block releasing label Sep 20, 2021
@mrivera-ms mrivera-ms added the backlog The issue is out of scope for the current iteration but it will be evaluated in a future release. label Sep 23, 2021
@mrivera-ms mrivera-ms modified the milestones: R15, r16 Sep 23, 2021
@jag43
Copy link

jag43 commented Jan 14, 2022

Just wanted to say I encountered the same error following this pluralsight course link

The above workaround fixed it 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backlog The issue is out of scope for the current iteration but it will be evaluated in a future release. Bot Services Required for internal Azure reporting. Do not delete. Do not change color. bug Indicates an unexpected problem or an unintended behavior. customer-replied-to Indicates that the team has replied to the issue reported by the customer. Do not delete. customer-reported Issue is created by anyone that is not a collaborator in the repository. needs-triage The issue has just been created and it has not been reviewed by the team. P1 Painful if we don't fix, won't block releasing
Projects
None yet
Development

No branches or pull requests

7 participants