SCIMReferenceCode icon indicating copy to clipboard operation
SCIMReferenceCode copied to clipboard

Json Serialization/Deserialization Issues

Open tsk46th3gAva opened this issue 3 years ago • 2 comments

I'm having troubles with the code running on a Azure App Service, that revolves around Json Converters. It seems like the conversions are being converted in Sample project differently that in the SCIM foundation project. Has anyone else seen this behavior?

An unhandled exception was thrown by the application.System.InvalidCastException: Unable to cast object of type 'Newtonsoft.Json.Linq.JObject' to type 'System.Collections.Generic.Dictionary2[System.String,System.Object]'.at Microsoft.SCIM.TrustedJsonFactory.Create(String json) in C:\source\Microsoft.SystemForCrossDomainIdentityManagement\Schemas\TrustedJsonFactory.cs:line 14at Microsoft.SCIM.JsonFactory.Create(String json, Boolean acceptLargeObjects) in C:\source\Microsoft.SystemForCrossDomainIdentityManagement\Schemas\JsonFactory.cs:line 35at Microsoft.SCIM.JsonSerializer.ToJson() in C:\source\Microsoft.SystemForCrossDomainIdentityManagement\Schemas\JsonSerializer.cs:line 76at Microsoft.SCIM.Schematized.ToJson() in C:\source\Microsoft.SystemForCrossDomainIdentityManagement\Schemas\Schematized.cs:line 111at Microsoft.SCIM.Core2UserBase.ToJson() in C:\source\Microsoft.SystemForCrossDomainIdentityManagement\Schemas\Core2UserBase.cs:line 168at Microsoft.SCIM.Schematized.Serialize() in C:\source\Microsoft.SystemForCrossDomainIdentityManagement\Schemas\Schematized.cs:line 118at Microsoft.SCIM.Schematized.ToString() in C:\source\Microsoft.SystemForCrossDomainIdentityManagement\Schemas\Schematized.cs:line 126at System.Convert.ToString(Object value, IFormatProvider provider)at System.Convert.ToString(Object value)at Microsoft.AspNetCore.Mvc.MvcCoreLoggerExtensions.ActionMethodExecuting(ILogger logger, ControllerContext context, Object[] arguments)at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeActionMethodAsync>g__Logged|12_1(ControllerActionInvoker invoker)at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeNextActionFilterAsync>g__Awaited|10_0(ControllerActionInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Rethrow(ActionExecutedContextSealed context)at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeInnerFilterAsync()--- End of stack trace from previous location where exception was thrown ---at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeFilterPipelineAsync>g__Awaited|19_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Logged|17_1(ResourceInvoker invoker)at Microsoft.AspNetCore.Routing.EndpointMiddleware.<Invoke>g__AwaitRequestTask|6_0(Endpoint endpoint, Task requestTask, ILogger logger)at Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpContext context)at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context)at Microsoft.AspNetCore.Server.IIS.Core.IISHttpContextOfT1.ProcessRequestAsync()

tsk46th3gAva avatar Jan 31 '22 21:01 tsk46th3gAva

I'm also facing this issue - same call-stack and exception. Did you manage to get anywhere with it or workaround it?

danieltwigden avatar Mar 31 '22 11:03 danieltwigden

For me the NewtonSoft/Json mismatch occurred when I added Microsoft.Extensions.Logging.AzureAppServices nuget to my solution. The package enables to see Logging data via ILogger, within App services. I removed it from my solution and the serialization errors went away.

For the issues I was able to trace, it seem like DateTime values were serialized into JavaScript form,

I've tried multiple things, to try to get ILogger working.

  1. using different versions of Microsoft.Extensions.Logging.AzureAppServices, I tried from the latest 6.0.3 to 3.1.23.
  2. Updating the NewtonSoft packages through the Microsoft.SCIM project, this seem to break more things, then fix.
  3. Updated and try removed the Json.net packaged.

tsk46th3gAva avatar Mar 31 '22 14:03 tsk46th3gAva