Prism.Container.Extensions
Prism.Container.Extensions copied to clipboard
Serialization Exception on Navigation Error
Description
When encountering a Navigation Error with no NavigationParameters an unhandled Serialization Exception is encountered while attempting to log the Navigation error.
Closing as I have been unable to reproduce the issue since it first occurred.
Hi @dansiegel , I think I encountered this unhandled Serialization Exception (or another problem, relative to navigationParameter Serialization) :
System.Runtime.Serialization.SerializationException: Type 'Prism.Navigation.NavigationParameters' with data contract name 'ArrayOfKeyValuePairOfstringanyType:http://schemas.datacontract.org/2004/07/System.Collections.Generic' is not expected. Add any types not known statically to the list of known types - for example, by using the KnownTypeAttribute attribute or by adding them to the list of known types passed to DataContractSerializer.
The StackTrace :
System.Runtime.Serialization.Json
XmlObjectSerializerWriteContextComplexJson.VerifyType (System.Runtime.Serialization.DataContract dataContract, System.Type declaredType)
System.Runtime.Serialization.Json
XmlObjectSerializerWriteContextComplexJson.HandleCollectionAssignedToObject (System.Type declaredType, System.Runtime.Serialization.DataContract& dataContract, System.Object& obj, System.Boolean& verifyKnownType)
System.Runtime.Serialization.Json
XmlObjectSerializerWriteContextComplexJson.SerializeWithXsiTypeAtTopLevel (System.Runtime.Serialization.DataContract dataContract, System.Runtime.Serialization.XmlWriterDelegator xmlWriter, System.Object obj, System.RuntimeTypeHandle originalDeclaredTypeHandle, System.Type graphType)
System.Runtime.Serialization.Json
DataContractJsonSerializer.InternalWriteObjectContent (System.Runtime.Serialization.XmlWriterDelegator writer, System.Object graph)
System.Runtime.Serialization.Json
DataContractJsonSerializer.InternalWriteObject (System.Runtime.Serialization.XmlWriterDelegator writer, System.Object graph)
System.Runtime.Serialization
XmlObjectSerializer.InternalWriteObject (System.Runtime.Serialization.XmlWriterDelegator writer, System.Object graph, System.Runtime.Serialization.DataContractResolver dataContractResolver)
System.Runtime.Serialization
XmlObjectSerializer.WriteObjectHandleExceptions (System.Runtime.Serialization.XmlWriterDelegator writer, System.Object graph, System.Runtime.Serialization.DataContractResolver dataContractResolver)
System.Runtime.Serialization
XmlObjectSerializer.WriteObjectHandleExceptions (System.Runtime.Serialization.XmlWriterDelegator writer, System.Object graph)
System.Runtime.Serialization.Json
DataContractJsonSerializer.WriteObject (System.Xml.XmlDictionaryWriter writer, System.Object graph)
System.Runtime.Serialization.Json
DataContractJsonSerializer.WriteObject (System.IO.Stream stream, System.Object graph)
Prism
PrismApplication.Serialize[T] (T instance)
Prism
PrismApplication.OnNavigationError (Prism.Events.INavigationError navigationError)
Tracio.Standard
TracioApp.OnNavigationError (Prism.Events.INavigationError navigationError)
Prism.Events
EventSubscription`1[TPayload].InvokeAction (System.Action`1[T] action, TPayload argument)
Prism.Events
EventSubscription`1+<>c__DisplayClass11_0[TPayload].<GetExecutionStrategy>b__0 (System.Object[] arguments)
Prism.Events
EventBase.InternalPublish (System.Object[] arguments)
Prism.Events
PubSubEvent`1[TPayload].Publish (TPayload payload)
Prism.Navigation
ErrorReportingNavigationService.NavigateInternal (System.Uri uri, Prism.Navigation.INavigationParameters parameters, System.Nullable`1[T] useModalNavigation, System.Boolean animated)
Tracio.Standard.ViewModels
MdPageViewModel.LoadPageAsync ()
It appear only after a PushNotification received, only with application in backgrounded state (it works correctly with application foregrounded, and application not launched), and only with DeepLinking Navigation behind (Prism Navigation, with a parameter -> if I do the same thing without parameter, there is no error). And the Navigation works (good deeplinked page is displayed), but impossible to get the parameter.
I'm working with these versions :
- Shiny.Core 1.2.0.1755
- Shiny.Prism 7.2.0.1054
- Prism.Forms.Extended 7.2.0.1054
- Prism.DryIoc.Extensions 7.2.0.1054
The Stacktrace talk about my "MDPageViewModel" in the "LoadPageAsync", and there is no special difficulty there (except the parameter ;-)) :
private async Task LoadPageAsync()
{
if (!string.IsNullOrWhiteSpace(_notificationService?.PendingUrl))
{
NavigationParameters param = new NavigationParameters();
param.Add("IsFromNotif", true);
await NavigationService.NavigateAsync(_notificationService.PendingUrl, param);
_notificationService.PendingUrl = null;
}
}
Maybe with another NavigationParameter syntax it may work... I'll do a try.
Any help or workaround would be very appreciated (currently I'm having this issue on a customer's application in production... with a lot of notifications)
Thanks
@Jerome-Liger I would suggest we discuss this more on Discord.
Ok Dan. For informations (it may help others), I've just wrapped this navigation in a "Device.InvokeOnMainThreadAsync(() => { [...] });" And it works like a charm and I don't get exception anymore... I thought it was just a background thread pb ;-)
HI, I've encountered this error too but I think it masks another error. I removed the navigationparameters from the call to navigate and I was able to see the actual exception in the navigation return parameter. Fixing this removed the Serialization Exception.
I've been trying to replicate this again but haven't been able to. if you can get me a demo that has the problem it would help me debug it and get a fix out.
OK will try but won't get chance for a little while....knee deep in having to completely rebuild my app as the (now required) AndroidX migration has trashed the old one to the point where it won't build.