Json.NET, Android/Xamarin and date serialization

In case you are using JSon.NET with Android/Xamarin you might encounter an “Object null reference” exception when trying to serialize (and probably deserialize as well) a type that contains DateTime property. The null object in question is TimeZoneInfo.Local.

This error happens when Android has no time zone set and thus Xamarin doesn’t set that property because it doesn’t know what time zone to use. There is a simple test where you can inspect Android’s time zone settings, just fire this command line:

adb shell getprop persist.sys.timezone

If it returns a blank line it means you are in trouble. A simple workaround for development is to set manually Android’s time zone through Settings/Date & Time or just fire another command line (i.e. setting time zone to Belgrade):

adb shell setprop persist.sys.timezone Europe/Belgrade

This works when using Genymotion emulator. Other than this there is no way to manually set the TimeZoneInfo.Local (perhaps it might be set through reflection, didn’t try it) which means your application won’t work in affected devices. Luckily the bug has been fixed and Xamarin will default to time zone defined by Java.Util.TimeZone.Default.ID. So, hopefully, the problem will go away for good.

Avtor: Anonymous, objavljeno na portalu SloDug.si (Arhiv)

Leave a comment

Please note that we won't show your email to others, or use it for sending unwanted emails. We will only use it to render your Gravatar image and to validate you as a real person.

fluethy
fluethy - sobota, 31. avgust 2024

In May of 2013, the carousel reopened in Luna Park and today, passengers can choose between 50 different beautifully hand- painted wooden horses <a href=https://enhanceyourlife.mom/>priligy dapoxetine 30mg</a> Here, we focused on microglia, which play a role in brain wiring refinement, and we investigated whether the control of these cells by 5 HT is relevant for neurodevelopment and spontaneous behaviors

DonaldDes
DonaldDes - sobota, 29. junij 2024

п»їbest mexican online pharmacies https://cmqpharma.online/# medication from mexico pharmacy mexican border pharmacies shipping to usa

StephenRip
StephenRip - sobota, 29. junij 2024

mexican online pharmacies prescription drugs: <a href=" http://cmqpharma.com/# ">medicine in mexico pharmacies</a> - purple pharmacy mexico price list