While attempting to JSON deserialize a collection in VB, I encountered the following issue.
Dim items = JsonConvert.DeserializeAnonymousType(Page.Request.Params("Items"), New List(Of ItemDto))
An error occurred during deserialization where the string "value" could not be null.
System.Web.HttpUnhandledException (0x80004005): Exception of type 'System.Web.HttpUnhandledException' was thrown. ---> System.ArgumentNullException: Value cannot be null.
Parameter name: value
at Newtonsoft.Json.JsonConvert.DeserializeObject(String value, Type type, JsonSerializerSettings settings)
at Newtonsoft.Json.JsonConvert.DeserializeObject[T](String value, JsonSerializerSettings settings)
The collection "Items" was stored in a
<asp:HiddenField runat="server" ClientIDMode="Static" ID="Items" />
which translates to <input type="hidden"....>
If I execute $("#Items').val(null);
before running with no items present, it functions correctly.
The question arises as to why does $("#Items").val();
display as "" both before and after setting it to null using $("#Items").val(null);
. Is there an invisible variation like a zero width space contributing to this difference?
The reason behind the code working after setting the collection to "null" remains unknown to me.
Thank you.