You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The BsonDataReader throws the following exception when deserializing byte[] that contains an array of integers:
Newtonsoft.Json.JsonSerializationException
HResult=0x80131500
Message=Cannot deserialize the current JSON object (e.g. {"name":"value"}) into type 'System.Int32[]' because the type requires a JSON array (e.g. [1,2,3]) to deserialize correctly.
To fix this error either change the JSON to a JSON array (e.g. [1,2,3]) or change the deserialized type so that it is a normal .NET type (e.g. not a primitive type like integer, not a collection type like an array or List) that can be deserialized from a JSON object. JsonObjectAttribute can also be added to the type to force it to deserialize from a JSON object.
Path '0'.
Source=Newtonsoft.Json
StackTrace:
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateObject(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize(JsonReader reader, Type objectType, Boolean checkAdditionalContent)
at Newtonsoft.Json.JsonSerializer.DeserializeInternal(JsonReader reader, Type objectType)
at PrlSystems.Serialization.ObjectSerializerUsingBsonFormatter.DeserializeObjectFromBytes(Byte[] bytes, SerializationSettings settings) in C:\PRL\DEV\Libs\CurrentLibraries\PrlSystemsLibrary\Serialization\ObjectSerializerUsingBsonFormatter.cs:line 54
at PrlSystems.Serialization.Base64SerializerUsingBsonFormatter.DeserializeObject(String str, SerializationSettings settings) in C:\PRL\DEV\Libs\CurrentLibraries\PrlSystemsLibrary\Serialization\Base64SerializerUsingBsonFormatter.cs:line 20
at PrlSystems.Serialization.SerializerUtil.DeserializeObjectFrom64Str(String str, IBase64Serializer serializer, SerializationSettings settings) in C:\PRL\DEV\Libs\CurrentLibraries\PrlSystemsLibrary\Serialization\SerializerUtil.cs:line 23
at Pimarcnet.WebAppCode.Shared.Web.QueryStringHelper.GetObjectFromQueryString(String objKey, Type type) in C:\PRL\DEV\Libs\CurrentLibraries\Pimarcnet.WebAppCode\Shared\Web\QueryStringHelper.cs:line 78
at Pimarcnet.WebAppCode.Shared.Web.QueryStringHelper.GetObjectFromQueryString[T](String objKey) in C:\PRL\DEV\Libs\CurrentLibraries\Pimarcnet.WebAppCode\Shared\Web\QueryStringHelper.cs:line 46
at Pimarcnet.Pages.Printout.PrintProjectData._GetCriteria() in C:\PRL\DEV\Pimarcnet\Pimarcnet\Pages\Printout\PrintProjectData.aspx.cs:line 29
at Pimarcnet.Pages.Printout.PrintProjectData._Init() in C:\PRL\DEV\Pimarcnet\Pimarcnet\Pages\Printout\PrintProjectData.aspx.cs:line 20
at Pimarcnet.Pages.Printout.PrintProjectData.Page_Load(Object sender, EventArgs e) in C:\PRL\DEV\Pimarcnet\Pimarcnet\Pages\Printout\PrintProjectData.aspx.cs:line 15
Here's the code (I included both serialization/deserialization code... Serialization code works, deserialization throws):
`var typeBeingSerialized = typeof(int[]);
JsonSerializer serializer = new JsonSerializer();
byte[] bytes;
int[] arr1 = { 1 };
using (var ms = new MemoryStream())
{
using (var writer = new BsonDataWriter(ms))
{
serializer.Serialize(writer, arr1, typeBeingSerialized);
bytes = ms.ToArray();
}
}
object result;
using (var ms = new MemoryStream(bytes))
{
using (var reader = new BsonDataReader(ms))
{
result = serializer.Deserialize(reader, typeBeingSerialized); // throws here!
}
}`
NOTE:
The Newtonsoft.json library handles of serializing/deserializing arrays. I have code for that if you need to see it.
The text was updated successfully, but these errors were encountered:
The BsonDataReader throws the following exception when deserializing byte[] that contains an array of integers:
Newtonsoft.Json.JsonSerializationException
HResult=0x80131500
Message=Cannot deserialize the current JSON object (e.g. {"name":"value"}) into type 'System.Int32[]' because the type requires a JSON array (e.g. [1,2,3]) to deserialize correctly.
To fix this error either change the JSON to a JSON array (e.g. [1,2,3]) or change the deserialized type so that it is a normal .NET type (e.g. not a primitive type like integer, not a collection type like an array or List) that can be deserialized from a JSON object. JsonObjectAttribute can also be added to the type to force it to deserialize from a JSON object.
Path '0'.
Source=Newtonsoft.Json
StackTrace:
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateObject(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize(JsonReader reader, Type objectType, Boolean checkAdditionalContent)
at Newtonsoft.Json.JsonSerializer.DeserializeInternal(JsonReader reader, Type objectType)
at PrlSystems.Serialization.ObjectSerializerUsingBsonFormatter.DeserializeObjectFromBytes(Byte[] bytes, SerializationSettings settings) in C:\PRL\DEV\Libs\CurrentLibraries\PrlSystemsLibrary\Serialization\ObjectSerializerUsingBsonFormatter.cs:line 54
at PrlSystems.Serialization.Base64SerializerUsingBsonFormatter.DeserializeObject(String str, SerializationSettings settings) in C:\PRL\DEV\Libs\CurrentLibraries\PrlSystemsLibrary\Serialization\Base64SerializerUsingBsonFormatter.cs:line 20
at PrlSystems.Serialization.SerializerUtil.DeserializeObjectFrom64Str(String str, IBase64Serializer serializer, SerializationSettings settings) in C:\PRL\DEV\Libs\CurrentLibraries\PrlSystemsLibrary\Serialization\SerializerUtil.cs:line 23
at Pimarcnet.WebAppCode.Shared.Web.QueryStringHelper.GetObjectFromQueryString(String objKey, Type type) in C:\PRL\DEV\Libs\CurrentLibraries\Pimarcnet.WebAppCode\Shared\Web\QueryStringHelper.cs:line 78
at Pimarcnet.WebAppCode.Shared.Web.QueryStringHelper.GetObjectFromQueryString[T](String objKey) in C:\PRL\DEV\Libs\CurrentLibraries\Pimarcnet.WebAppCode\Shared\Web\QueryStringHelper.cs:line 46
at Pimarcnet.Pages.Printout.PrintProjectData._GetCriteria() in C:\PRL\DEV\Pimarcnet\Pimarcnet\Pages\Printout\PrintProjectData.aspx.cs:line 29
at Pimarcnet.Pages.Printout.PrintProjectData._Init() in C:\PRL\DEV\Pimarcnet\Pimarcnet\Pages\Printout\PrintProjectData.aspx.cs:line 20
at Pimarcnet.Pages.Printout.PrintProjectData.Page_Load(Object sender, EventArgs e) in C:\PRL\DEV\Pimarcnet\Pimarcnet\Pages\Printout\PrintProjectData.aspx.cs:line 15
Here's the code (I included both serialization/deserialization code... Serialization code works, deserialization throws):
`var typeBeingSerialized = typeof(int[]);
JsonSerializer serializer = new JsonSerializer();
byte[] bytes;
int[] arr1 = { 1 };
using (var ms = new MemoryStream())
{
using (var writer = new BsonDataWriter(ms))
{
serializer.Serialize(writer, arr1, typeBeingSerialized);
bytes = ms.ToArray();
}
}
object result;
using (var ms = new MemoryStream(bytes))
{
using (var reader = new BsonDataReader(ms))
{
result = serializer.Deserialize(reader, typeBeingSerialized); // throws here!
}
}`
NOTE:
The Newtonsoft.json library handles of serializing/deserializing arrays. I have code for that if you need to see it.
The text was updated successfully, but these errors were encountered: