JSON Deserialization of Byte Arrays not working in MultiSelect Dropdown

Hi Support,

I've encountered this bug when adding an ItemTemplate component inside of a MultiSelect Dropdown.

Below is a Product class (used for the entities of the Dropdown), which includes a byte[] Version field.

public class Product
{
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public Guid Id { get; set; }
public string BrandName { get; set; }

public byte[] Version { get; set; }
}

Below is a Blazor Component file using SfMultiSelect with ItemTemplate.
@code {
[Parameter]
public string Id { get; set; }

[Inject]
private IODataEndpointProvider EndpointProvider { get; set; }

Type ProductType { get; set; } = typeof(Product);
}

<SfMultiSelect ModelType="@ProductType" ID="@Id" TValue="string[]" Placeholder="Products" Mode="VisualMode.CheckBox" AllowFiltering="true">
<MultiSelectTemplates>
<ItemTemplate>
<span class="item">
<span class="brand-name">@((context as Product)?.BrandName) (Extra Info Here)</span>
</span>
</ItemTemplate>
</MultiSelectTemplates>
<SfDataManager Url="@EndpointProvider.ProductsEndpoint" Adaptor="Adaptors.ODataV4Adaptor"></SfDataManager>
<MultiSelectFieldSettings Value="Id" Text="@nameof(Product.BrandName)"/>
</SfMultiSelect>
When running, there appears to be a deserialization issue when clicking on this MultiSelect in the browser:

Microsoft.AspNetCore.Components.WebAssembly.Rendering.WebAssemblyRenderer[100]
      Unhandled exception rendering component: Unexpected character encountered while parsing value: A. Path '', line 1, position 1.
Newtonsoft.Json.JsonReaderException: Unexpected character encountered while parsing value: A. Path '', line 1, position 1.
   at Newtonsoft.Json.JsonTextReader.ReadAsBytes()
   at Newtonsoft.Json.JsonReader.ReadForType(JsonContract contract, Boolean hasConverter)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize(JsonReader reader, Type objectType, Boolean checkAdditionalContent)
   at Newtonsoft.Json.JsonSerializer.DeserializeInternal(JsonReader reader, Type objectType)
   at Newtonsoft.Json.JsonSerializer.Deserialize(JsonReader reader, Type objectType)
   at Newtonsoft.Json.JsonConvert.DeserializeObject(String value, Type type, JsonSerializerSettings settings)
   at Syncfusion.Blazor.Internal.SfBaseUtils.ChangeType(Object dataValue, Type conversionType, Boolean isClientChange)
   at Syncfusion.Blazor.BaseComponent.GetObject(Dictionary`2 Data, Type ModelType)
   at Syncfusion.Blazor.DropDowns.MultiSelectTemplates.BuildRenderTree(RenderTreeBuilder __builder)
   at Microsoft.AspNetCore.Components.ComponentBase.<.ctor>b__6_0(RenderTreeBuilder builder)
   at Microsoft.AspNetCore.Components.Rendering.ComponentState.RenderIntoBatch(RenderBatchBuilder batchBuilder, RenderFragment renderFragment)
   at Microsoft.AspNetCore.Components.RenderTree.Renderer.RenderInExistingBatch(RenderQueueEntry renderQueueEntry)
   at Microsoft.AspNetCore.Components.RenderTree.Renderer.ProcessRenderQueue()

Deleting the Version field stops this error and the Template shows correctly. By looking at the response from the OData endpoint containing the products, we see that all the version fields are 64bit encoded:

[
  {
Id: "11111111-2222-3333-4444-555555555555"
    BrandName: "TestName"
Version: "AAAAAAAAB/k="
},
...
]

So that 'Unexpected character: A' on line 2 of the error must be from trying to deserialize the Version field.

I'd like to keep the Version field on this entity for concurrency purposes - should I do something differently to get this working?

3 Replies

VS Vignesh Srinivasan Syncfusion Team December 14, 2020 05:17 PM UTC

Hi Perry Jones, 
 
We have created the sample based on your scenario and shared code snippet. We have used the shared dataSource item in our code and kept Version field as byte[] and checked the reported issue. We could not replicate it in our end. Please find the sample link below  
  
  
 Kindly check with the above sample in your end. If the issue still persist, kindly replicate the issue in above sample or else provide issue replicating sample. Also please share your demo Odata dataSource to proceed further. 
 
Regards, 
 
Vignesh Srinivasan. 



PJ Perry Jones December 14, 2020 05:34 PM UTC

Hi Vignesh,

I've opened up your project, but your example uses a local data source.

My question was on the JSON deserialization of byte arrays from an OData endpoint. 

The OData endpoint returns the following HTTP Response:

{
     "@odata.context":"https://localhost:44395/odata/$metadata#Products",
     "value":[
          {
               Id: "11111111-2222-3333-4444-555555555555"
               BrandName: "TestName"
               Version: "AAAAAAAAB/k="
          },
        ...
     ]
}

Hopefully you can replicate this on your end with the extra info.



SP Sureshkumar P Syncfusion Team December 24, 2020 12:01 PM UTC

Hi Perry, 
 
Thanks for your patience.  
 
We have created the sample with byte arrays from an OData endpoint. But we cannot able to replicate the reported issue from our end. please find the front and backend sample below link. 
 
 
 
Regards, 
Sureshkumar P 


Loader.
Up arrow icon