New Json class in DNN 7.1 throw Exception when used with french language.
Add an Answer
Your question has been submitted and is awaiting moderation.
Thank you for reporting this content, moderators have been notified of your submission.
I have some new exceptions when using a self-developed module since I updated to 7.1.1
Message: DotNetNuke.Services.Exceptions.PageLoadException: Une erreur s'est produite lors de la désérialisation de l'objet de type DotNetNuke.Web.UI.WebControls.DnnDropDownListState. Jeton '"' attendu, mais 'Å' a été trouvé. ---> System.Runtime.Serialization.SerializationException: Une erreur s'est produite lors de la désérialisation de l'objet de type DotNetNuke.Web.UI.WebControls.DnnDropDownListState. Jeton '"' attendu, mais 'Å' a été trouvé.
Looking into DNN source code, it appears that some new files (in .1.1 which where not present in 7.0.6) may explain the new bug(see below) .
Does anybody encounter the same problem ?
How to submit the bug to DNN developers ?
new web control : namespace DotNetNuke.Web.UI.WebControls :DnnDropDownList
new utility : amespace DotNetNuke.Common.Utilities : Json
Looking at the source code of JSON, it appears that serialization is using Encoding.Default, but deserialization is using Encoding;Unicode. (See code below) When using Encoding default for both serialization and deserialization, (and recompiling the DotNetNuke.dll, it appears to be OK.
BUT, I'M NOT SURE AND DO NOT WANT to modify the DNN VERSION on my Production site !
If Anyone at DNN can help, and may be report the bug ...
public static class Json
{
public static T Deserialize(string json)
{
var obj = Activator.CreateInstance();
// using (var ms = new MemoryStream(Encoding.Unicode.GetBytes(json)))
//Jean-Luc PETITCLERC : modifying Encoding to Default seems to resolve my bugs ?
using (var ms = new MemoryStream(Encoding.Default.GetBytes(json)))
{
var serializer = new DataContractJsonSerializer(obj.GetType());
obj = (T) serializer.ReadObject(ms);
return obj;
}
}
public static string Serialize(T obj)
{
var serializer = new DataContractJsonSerializer(obj.GetType());
using (var ms = new MemoryStream())
{
serializer.WriteObject(ms, obj);
return Encoding.Default.GetString(ms.ToArray());
}
}
}