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

Getting Error reading JObject from JsonReader. Current JsonReader item is not an object: String. Path 'userPurpose' in the Demo project. #43

Closed
1 task
spartan1047 opened this issue May 13, 2022 · 6 comments · Fixed by #44
Labels
bug Issue is a bug in the code in this repository fixed Fix is complete and will be available to customers as soon as doc updates are published

Comments

@spartan1047
Copy link

spartan1047 commented May 13, 2022

Where did you get the code?

Describe the bug
Is not possible to get the MailboxSettings with the projects as it is. If you run the project you get a Newtonsoft.Json.JsonReaderException, this happen following the tutorial o downloading the demo project from github, in both cases I have replaced the AppID with my own id.
To Reproduce
Steps to reproduce the behavior (for the demo):

  1. Open the solution
  2. Rename the OAuth.resw.example to OAuth.resw
  3. Added my AppID
  4. Run the app
  5. Login with my account
  6. The app displays my name over the top-right corrner.
  7. Press Calendar.
  8. The exception is displayed.

Expected behavior
I'm expecting to see the calendar as the tutorial and documentation indicates.

Screenshots

Bug Graph

Desktop (please complete the following information):

  • OS: [e.g. iOS]
  • Browser [e.g. chrome, safari]
  • Version [e.g. 22]

Dependency versions

  • Authentication library (MSAL, etc.) version:
  • Graph library (Graph SDK, REST library, etc.) version:

Additional context
Exception output:
Newtonsoft.Json.JsonReaderException
HResult=0x80131500
Mensaje = Error reading JObject from JsonReader. Current JsonReader item is not an object: String. Path 'userPurpose', line 1, position 492.
Origen = Newtonsoft.Json
Seguimiento de la pila:
en Newtonsoft.Json.Linq.JObject.Load(JsonReader reader, JsonLoadSettings settings)
en Microsoft.Graph.DerivedTypeConverter.ReadJson(JsonReader reader, Type objectType, Object existingValue, JsonSerializer serializer)
en Newtonsoft.Json.Serialization.JsonSerializerInternalReader.DeserializeConvertable(JsonConverter converter, JsonReader reader, Type objectType, Object existingValue)
en Newtonsoft.Json.Serialization.JsonSerializerInternalReader.SetPropertyValue(JsonProperty property, JsonConverter propertyConverter, JsonContainerContract containerContract, JsonProperty containerProperty, JsonReader reader, Object target)
en Newtonsoft.Json.Serialization.JsonSerializerInternalReader.PopulateObject(Object newObject, JsonReader reader, JsonObjectContract contract, JsonProperty member, String id)
en Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Populate(JsonReader reader, Object target)
en Microsoft.Graph.DerivedTypeConverter.ReadJson(JsonReader reader, Type objectType, Object existingValue, JsonSerializer serializer)
en Newtonsoft.Json.Serialization.JsonSerializerInternalReader.DeserializeConvertable(JsonConverter converter, JsonReader reader, Type objectType, Object existingValue)
en Newtonsoft.Json.Serialization.JsonSerializerInternalReader.SetPropertyValue(JsonProperty property, JsonConverter propertyConverter, JsonContainerContract containerContract, JsonProperty containerProperty, JsonReader reader, Object target)
en Newtonsoft.Json.Serialization.JsonSerializerInternalReader.PopulateObject(Object newObject, JsonReader reader, JsonObjectContract contract, JsonProperty member, String id)
en Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Populate(JsonReader reader, Object target)
en Microsoft.Graph.DerivedTypeConverter.ReadJson(JsonReader reader, Type objectType, Object existingValue, JsonSerializer serializer)
en Newtonsoft.Json.Serialization.JsonSerializerInternalReader.DeserializeConvertable(JsonConverter converter, JsonReader reader, Type objectType, Object existingValue)
en Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize(JsonReader reader, Type objectType, Boolean checkAdditionalContent)
en Newtonsoft.Json.JsonSerializer.DeserializeInternal(JsonReader reader, Type objectType)
en Newtonsoft.Json.JsonConvert.DeserializeObject(String value, Type type, JsonSerializerSettings settings)
en Newtonsoft.Json.JsonConvert.DeserializeObject[T](String value, JsonSerializerSettings settings)
en Microsoft.Graph.Serializer.DeserializeObject[T](String inputString)
en Microsoft.Graph.ResponseHandler.d__21.MoveNext() en System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() en System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) en Microsoft.Graph.BaseRequest.<SendAsync>d__341.MoveNext()
en System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
en System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
en Microsoft.Graph.UserRequest.d__6.MoveNext()
en System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
en System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
en System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
en GraphTutorial.CalendarPage.d__2.MoveNext() en C:\Users\Alienware Alpha\source\repos\GraphTutorial\GraphTutorial\CalendarPage.xaml.cs: línea 52

Esta excepción se generó originalmente en esta pila de llamadas:
[Código externo]
GraphTutorial.CalendarPage.OnNavigatedTo(Windows.UI.Xaml.Navigation.NavigationEventArgs) en CalendarPage.xaml.cs

@ghost ghost added the needs triage 🔍 New issue, needs triage label May 13, 2022
@jasonjoh
Copy link
Member

@spartan1047 sorry you're having trouble! This seems to be an issue with the very old version of the Graph SDK that the (deprecated) Microsoft.Toolkit.Graph.Controls package. The userPurpose field was added to mailboxSettings after that version was released.

I suspect the answer here will be to replace Microsoft.Toolkit.Graph.Controls with CommunityToolkit.Graph.Uwp. I'm not sure how much effort that entails at this point, but I'll take a look ASAP.

@jasonjoh jasonjoh added bug Issue is a bug in the code in this repository and removed needs triage 🔍 New issue, needs triage labels May 13, 2022
jasonjoh added a commit that referenced this issue May 16, 2022
Microsoft.Toolkit.Graph.* is deprecated, the recommended replacement is CommunityToolkit.Graph.

Fixes #43
@ghost ghost added the in pr An open PR addresses this issue label May 16, 2022
@ghost ghost added fixed Fix is complete and will be available to customers as soon as doc updates are published and removed in pr An open PR addresses this issue labels May 16, 2022
@spartan1047
Copy link
Author

@jasonjoh Hello, thanks for the commit, I have downloaded the changes but still not working, in Windows 10, after I type my password nothing happens. In Windows 11, I'm getting an error:
MicrosoftTeams-image

@jasonjoh
Copy link
Member

Oh yes, sorry! This is an issue with the new toolkit (see CommunityToolkit/Graph-Controls#188). For now add the redirect URI the error is showing you to your app registration (under Authentication).

@jasonjoh
Copy link
Member

Better solution:

// Configure MSAL provider
var msalClient = PublicClientApplicationBuilder.Create(appId)
    .WithRedirectUri("https://login.microsoftonline.com/common/oauth2/nativeclient")
    .Build();
ProviderManager.Instance.GlobalProvider = new MsalProvider(msalClient, scopes.Split(' '));

Commit incoming.

@spartan1047
Copy link
Author

Thank you for the help, I have downloaded the latest version of the project, but the behavior is a little bit weird. When I run the app for first time (or when I'm not logged in) after I type my password the app freezes and displayes this dialog:

image

If I close it, I return tot he UWP logged in.

@jasonjoh
Copy link
Member

@ghost ghost locked as resolved and limited conversation to collaborators Jun 10, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Issue is a bug in the code in this repository fixed Fix is complete and will be available to customers as soon as doc updates are published
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants