PlatformNotSupportedException when serializing

1,632 views
Skip to first unread message

marcus

unread,
Aug 19, 2019, 9:59:13 AM8/19/19
to RavenDB - 2nd generation document database
I'm using RavenDB.Identity with Google authentication but when I try to to add the new Login I get the following exception. Do you have any idea whats going on here?


fail: Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware[1]
     
An unhandled exception has occurred while executing the request.
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation.
 
---> System.PlatformNotSupportedException: This instance contains state that cannot be serialized and deserialized on this platform.
   at
System.Security.Claims.ClaimsPrincipal.OnSerializingMethod(StreamingContext context)
   
--- End of inner exception stack trace ---
   at
System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor, Boolean wrapExceptions)
   at
System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   at
System.Reflection.MethodBase.Invoke(Object obj, Object[] parameters)
   at
Newtonsoft.Json.Serialization.JsonContract.<>c__DisplayClass57_0.<CreateSerializationCallback>b__0(Object o, StreamingContext context)
   at
Newtonsoft.Json.Serialization.JsonContract.InvokeOnSerializing(Object o, StreamingContext context)
   at
Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.OnSerializing(JsonWriter writer, JsonContract contract, Object value)
   at
Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeObject(JsonWriter writer, Object value, JsonObjectContract contract, JsonProperty member, JsonContainerContract collectionContract, JsonProperty containerProperty)
   at
Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeValue(JsonWriter writer, Object value, JsonContract valueContract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerProperty)
   at
Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeObject(JsonWriter writer, Object value, JsonObjectContract contract, JsonProperty member, JsonContainerContract collectionContract, JsonProperty containerProperty)
   at
Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeValue(JsonWriter writer, Object value, JsonContract valueContract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerProperty)
   at
Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeList(JsonWriter writer, IEnumerable values, JsonArrayContract contract, JsonProperty member, JsonContainerContract collectionContract, JsonProperty containerProperty)
   at
Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeValue(JsonWriter writer, Object value, JsonContract valueContract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerProperty)
   at
Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeObject(JsonWriter writer, Object value, JsonObjectContract contract, JsonProperty member, JsonContainerContract collectionContract, JsonProperty containerProperty)
   at
Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeValue(JsonWriter writer, Object value, JsonContract valueContract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerProperty)
   at
Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.Serialize(JsonWriter jsonWriter, Object value, Type objectType)
   at
Newtonsoft.Json.JsonSerializer.SerializeInternal(JsonWriter jsonWriter, Object value, Type objectType)
   at
Newtonsoft.Json.JsonSerializer.Serialize(JsonWriter jsonWriter, Object value)
   at
Raven.Client.Documents.Session.EntityToBlittable.ConvertEntityToBlittable(Object entity, DocumentInfo documentInfo) in C:\Builds\RavenDB-Stable-4.2\42017\src\Raven.Client\Documents\Session\EntityToBlittable.cs:line 43
   at
Raven.Client.Documents.Session.InMemoryDocumentSessionOperations.PrepareForEntitiesPuts(SaveChangesData result) in C:\Builds\RavenDB-Stable-4.2\42017\src\Raven.Client\Documents\Session\InMemoryDocumentSessionOperations.cs:line 971
   at
Raven.Client.Documents.Session.InMemoryDocumentSessionOperations.PrepareForSaveChanges() in C:\Builds\RavenDB-Stable-4.2\42017\src\Raven.Client\Documents\Session\InMemoryDocumentSessionOperations.cs:line 800
   at
Raven.Client.Documents.Session.Operations.BatchOperation.CreateRequest() in C:\Builds\RavenDB-Stable-4.2\42017\src\Raven.Client\Documents\Session\Operations\BatchOperation.cs:line 32
   at
Raven.Client.Documents.Session.AsyncDocumentSession.SaveChangesAsync(CancellationToken token) in C:\Builds\RavenDB-Stable-4.2\42017\src\Raven.Client\Documents\Session\AsyncDocumentSession.cs:line 135
   at
WebApp3.RavenSaveChangesAsyncFilter.OnPageHandlerExecutionAsync(PageHandlerExecutingContext context, PageHandlerExecutionDelegate next) in /Users/marcus/Temp/WebApp3/Startup.cs:line 181
   at
Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure.PageActionInvoker.InvokeNextPageFilterAsync()
   at
Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure.PageActionInvoker.Rethrow(PageHandlerExecutedContext context)
   at
Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure.PageActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
   at
Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure.PageActionInvoker.InvokeInnerFilterAsync()
   at
Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeNextResourceFilter>g__Awaited|24_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
   at
Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Rethrow(ResourceExecutedContextSealed context)
   at
Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
   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.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)


Oren Eini (Ayende Rahien)

unread,
Aug 19, 2019, 12:15:30 PM8/19/19
to ravendb
ClaimsPrincipal is likely having some serialization behavior being invoked by JSON.Net ?

--
You received this message because you are subscribed to the Google Groups "RavenDB - 2nd generation document database" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ravendb+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ravendb/7e6de3d5-f0cd-480d-8ff5-32e774431123%40googlegroups.com.


--
Oren Eini
CEO   /   Hibernating Rhinos LTD
Skype:  ayenderahien
Support:  sup...@ravendb.net

marcus

unread,
Aug 19, 2019, 1:12:40 PM8/19/19
to RavenDB - 2nd generation document database
Yes, I guess that is whats going on. It seems to be in combination with this filter I'm using https://github.com/JudahGabriel/RavenDB.Identity/blob/0be77c255a717a8edbde843b15139baeb3ac08d0/Samples/RazorPages/Filters/RavenSaveChangesAsyncFilter.cs

I use the following page filter and it seems to be an issue with it. Maybe it runs in the wrong order or something?
To unsubscribe from this group and stop receiving emails from it, send an email to rav...@googlegroups.com.

Oren Eini (Ayende Rahien)

unread,
Aug 20, 2019, 8:16:08 AM8/20/19
to ravendb
I think that you shouldn't have ClaimPrincipal serialized, or write a JsonConverter for it

To unsubscribe from this group and stop receiving emails from it, send an email to ravendb+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ravendb/f94cdf18-df2f-42e1-9e16-90286d406ad4%40googlegroups.com.

Judah Gabriel Himango

unread,
Aug 30, 2019, 10:54:11 AM8/30/19
to RavenDB - 2nd generation document database
Just to close the loop on this, the issue turned out to be Newtonsoft.Json being unable to serializing claims, principals and identities from Google Authentication. You can workaround the issue by providing a custom claim serializer to Raven.
Reply all
Reply to author
Forward
0 new messages