When selecting a derived type ystem.Text.Json.JsonException is thrown

Hi,

I have a dropdown with TValue set to base class. But when i selected an item of a derived type i get exception as you see at the bottom of this post. I have made a small sample to reproduce it.  Am i doing something wrong or is it a bug ? 

Example

@page "/test"


<SfDropDownList

                TItem="ModelA"

                TValue="ModelA"

                DataSource="@Test">

    <DropDownListFieldSettings Text="TextA" Value="TextA" />

</SfDropDownList>


@code

{

    public List<ModelA> Test = new List<ModelA>

    {

        new ModelA() { TextA = "1" },

        new ModelB() { TextA = "2", TextB = "3" }

    };


    public class ModelA

    {

        public string TextA { get; set; } = string.Empty;

    }


    public class ModelB : ModelA

    {

        public string TextB { get; set; } = string.Empty;

    }

}



StackTrace:

crit: Microsoft.AspNetCore.Components.WebAssembly.Rendering.WebAssemblyRenderer[100]

      Unhandled exception rendering component: 'E' is an invalid start of a value. Path: $ | LineNumber: 0 | BytePositionInLine: 0.

System.Text.Json.JsonException: 'E' is an invalid start of a value. Path: $ | LineNumber: 0 | BytePositionInLine: 0.

 ---> System.Text.Json.JsonReaderException: 'E' is an invalid start of a value. LineNumber: 0 | BytePositionInLine: 0.

   at System.Text.Json.ThrowHelper.ThrowJsonReaderException(Utf8JsonReader& json, ExceptionResource resource, Byte nextByte, ReadOnlySpan`1 bytes)

   at System.Text.Json.Utf8JsonReader.ConsumeValue(Byte marker)

   at System.Text.Json.Utf8JsonReader.ReadFirstToken(Byte first)

   at System.Text.Json.Utf8JsonReader.ReadSingleSegment()

   at System.Text.Json.Utf8JsonReader.Read()

   at System.Text.Json.Serialization.JsonConverter`1[[Energinet.FrontEndWeb.Client.BusinessAreas.Fskar.Pages.InterconnectorMeteringDocuments___Copy.ModelA, Energinet.FrontEndWeb.Client, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]].ReadCore(Utf8JsonReader& reader, JsonSerializerOptions options, ReadStack& state)

   --- End of inner exception stack trace ---

   at System.Text.Json.ThrowHelper.ReThrowWithPath(ReadStack& state, JsonReaderException ex)

   at System.Text.Json.Serialization.JsonConverter`1[[Energinet.FrontEndWeb.Client.BusinessAreas.Fskar.Pages.InterconnectorMeteringDocuments___Copy.ModelA, Energinet.FrontEndWeb.Client, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]].ReadCore(Utf8JsonReader& reader, JsonSerializerOptions options, ReadStack& state)

   at System.Text.Json.Serialization.JsonConverter`1[[Energinet.FrontEndWeb.Client.BusinessAreas.Fskar.Pages.InterconnectorMeteringDocuments___Copy.ModelA, Energinet.FrontEndWeb.Client, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]].ReadCoreAsObject(Utf8JsonReader& reader, JsonSerializerOptions options, ReadStack& state)

   at System.Text.Json.JsonSerializer.ReadFromSpan[Object](ReadOnlySpan`1 utf8Json, JsonTypeInfo jsonTypeInfo, Nullable`1 actualByteCount)

   at System.Text.Json.JsonSerializer.ReadFromSpan[Object](ReadOnlySpan`1 json, JsonTypeInfo jsonTypeInfo)

   at System.Text.Json.JsonSerializer.Deserialize(String json, Type returnType, JsonSerializerOptions options)

   at Syncfusion.Blazor.Internal.SfBaseUtils.ChangeType(Object dataValue, Type conversionType, Boolean isClientChange, Boolean isParseValue)

   at Syncfusion.Blazor.DropDowns.SfDropDownList`2[[Energinet.FrontEndWeb.Client.BusinessAreas.Fskar.Pages.InterconnectorMeteringDocuments___Copy.ModelA, Energinet.FrontEndWeb.Client, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null],[Energinet.FrontEndWeb.Client.BusinessAreas.Fskar.Pages.InterconnectorMeteringDocuments___Copy.ModelA, Energinet.FrontEndWeb.Client, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]].GetItemData(ModelA item)

   at Syncfusion.Blazor.DropDowns.SfDropDownList`2.<SetValue>d__491[[Energinet.FrontEndWeb.Client.BusinessAreas.Fskar.Pages.InterconnectorMeteringDocuments___Copy.ModelA, Energinet.FrontEndWeb.Client, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null],[Energinet.FrontEndWeb.Client.BusinessAreas.Fskar.Pages.InterconnectorMeteringDocuments___Copy.ModelA, Energinet.FrontEndWeb.Client, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]].MoveNext()

   at Syncfusion.Blazor.DropDowns.SfDropDownList`2.<SetSelectOptions>d__490[[Energinet.FrontEndWeb.Client.BusinessAreas.Fskar.Pages.InterconnectorMeteringDocuments___Copy.ModelA, Energinet.FrontEndWeb.Client, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null],[Energinet.FrontEndWeb.Client.BusinessAreas.Fskar.Pages.InterconnectorMeteringDocuments___Copy.ModelA, Energinet.FrontEndWeb.Client, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]].MoveNext()

   at Syncfusion.Blazor.DropDowns.SfDropDownList`2.<UpdateSelectItem>d__488[[Energinet.FrontEndWeb.Client.BusinessAreas.Fskar.Pages.InterconnectorMeteringDocuments___Copy.ModelA, Energinet.FrontEndWeb.Client, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null],[Energinet.FrontEndWeb.Client.BusinessAreas.Fskar.Pages.InterconnectorMeteringDocuments___Copy.ModelA, Energinet.FrontEndWeb.Client, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]].MoveNext()

   at Syncfusion.Blazor.DropDowns.SfDropDownList`2.<UpdateSelectedItem>d__487[[Energinet.FrontEndWeb.Client.BusinessAreas.Fskar.Pages.InterconnectorMeteringDocuments___Copy.ModelA, Energinet.FrontEndWeb.Client, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null],[Energinet.FrontEndWeb.Client.BusinessAreas.Fskar.Pages.InterconnectorMeteringDocuments___Copy.ModelA, Energinet.FrontEndWeb.Client, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]].MoveNext()

   at Syncfusion.Blazor.DropDowns.SfDropDownList`2.<OnMouseClick>d__485[[Energinet.FrontEndWeb.Client.BusinessAreas.Fskar.Pages.InterconnectorMeteringDocuments___Copy.ModelA, Energinet.FrontEndWeb.Client, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null],[Energinet.FrontEndWeb.Client.BusinessAreas.Fskar.Pages.InterconnectorMeteringDocuments___Copy.ModelA, Energinet.FrontEndWeb.Client, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]].MoveNext()

   at Microsoft.AspNetCore.Components.ComponentBase.CallStateHasChangedOnAsyncCompletion(Task task)

   at Microsoft.AspNetCore.Components.RenderTree.Renderer.GetErrorHandledTask(Task taskToHandle, ComponentState owningComponentState)

window.Module.s.printErr @ blazor.webassembly.js:1

Fe._internal.dotNetCriticalError @ blazor.webassembly.js:1

St @ blazor.webassembly.js:1

_mono_wasm_invoke_js_blazor @ dotnet.6.0.5.5871iht38f.js:1

$func219 @ 00971e46:0x1a490

$func167 @ 00971e46:0xce5e

$func166 @ 00971e46:0xbd71

$func2812 @ 00971e46:0xabf01

$func1616 @ 00971e46:0x6fcc2

$func1614 @ 00971e46:0x6fc34

$func967 @ 00971e46:0x50685

$func219 @ 00971e46:0x1a449

$func167 @ 00971e46:0xce5e

$func166 @ 00971e46:0xbd71

$func2812 @ 00971e46:0xabf01

$func1616 @ 00971e46:0x6fcc2

$func1620 @ 00971e46:0x7032f

$mono_wasm_invoke_method @ 00971e46:0x969d

Module._mono_wasm_invoke_method @ dotnet.6.0.5.5871iht38f.js:1

managed__Microsoft_AspNetCore_Components_WebAssembly__Microsoft_AspNetCore_Components_WebAssembly_Services_DefaultWebAssemblyJSRuntime_BeginInvokeDotNet @ managed__Microsoft_AspNetCore_Components_WebAssembly__Microsoft_AspNetCore_Components_WebAssembly_Services_DefaultWebAssemblyJSRuntime_BeginInvokeDotNet:19

beginInvokeDotNetFromJS @ blazor.webassembly.js:1

b @ blazor.webassembly.js:1

invokeMethodAsync @ blazor.webassembly.js:1

(anonymous) @ blazor.webassembly.js:1

invokeWhenHeapUnlocked @ blazor.webassembly.js:1

A @ blazor.webassembly.js:1

N @ blazor.webassembly.js:1

dispatchGlobalEventToAllElements @ blazor.webassembly.js:1

onGlobalEvent @ blazor.webassembly.js:1

blazor.webassembly.js:1 crit: Microsoft.AspNetCore.Components.WebAssembly.Rendering.WebAssemblyRenderer[100]

      Unhandled exception rendering component: 'E' is an invalid start of a value. Path: $ | LineNumber: 0 | BytePositionInLine: 0.

System.Text.Json.JsonException: 'E' is an invalid start of a value. Path: $ | LineNumber: 0 | BytePositionInLine: 0.

 ---> System.Text.Json.JsonReaderException: 'E' is an invalid start of a value. LineNumber: 0 | BytePositionInLine: 0.

   at System.Text.Json.ThrowHelper.ThrowJsonReaderException(Utf8JsonReader& json, ExceptionResource resource, Byte nextByte, ReadOnlySpan`1 bytes)

   at System.Text.Json.Utf8JsonReader.ConsumeValue(Byte marker)

   at System.Text.Json.Utf8JsonReader.ReadFirstToken(Byte first)

   at System.Text.Json.Utf8JsonReader.ReadSingleSegment()

   at System.Text.Json.Utf8JsonReader.Read()

   at System.Text.Json.Serialization.JsonConverter`1[[Energinet.FrontEndWeb.Client.BusinessAreas.Fskar.Pages.InterconnectorMeteringDocuments___Copy.ModelA, Energinet.FrontEndWeb.Client, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]].ReadCore(Utf8JsonReader& reader, JsonSerializerOptions options, ReadStack& state)

   --- End of inner exception stack trace ---

   at System.Text.Json.ThrowHelper.ReThrowWithPath(ReadStack& state, JsonReaderException ex)

   at System.Text.Json.Serialization.JsonConverter`1[[Energinet.FrontEndWeb.Client.BusinessAreas.Fskar.Pages.InterconnectorMeteringDocuments___Copy.ModelA, Energinet.FrontEndWeb.Client, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]].ReadCore(Utf8JsonReader& reader, JsonSerializerOptions options, ReadStack& state)

   at System.Text.Json.Serialization.JsonConverter`1[[Energinet.FrontEndWeb.Client.BusinessAreas.Fskar.Pages.InterconnectorMeteringDocuments___Copy.ModelA, Energinet.FrontEndWeb.Client, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]].ReadCoreAsObject(Utf8JsonReader& reader, JsonSerializerOptions options, ReadStack& state)

   at System.Text.Json.JsonSerializer.ReadFromSpan[Object](ReadOnlySpan`1 utf8Json, JsonTypeInfo jsonTypeInfo, Nullable`1 actualByteCount)

   at System.Text.Json.JsonSerializer.ReadFromSpan[Object](ReadOnlySpan`1 json, JsonTypeInfo jsonTypeInfo)

   at System.Text.Json.JsonSerializer.Deserialize(String json, Type returnType, JsonSerializerOptions options)

   at Syncfusion.Blazor.Internal.SfBaseUtils.ChangeType(Object dataValue, Type conversionType, Boolean isClientChange, Boolean isParseValue)

   at Syncfusion.Blazor.DropDowns.SfDropDownList`2[[Energinet.FrontEndWeb.Client.BusinessAreas.Fskar.Pages.InterconnectorMeteringDocuments___Copy.ModelA, Energinet.FrontEndWeb.Client, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null],[Energinet.FrontEndWeb.Client.BusinessAreas.Fskar.Pages.InterconnectorMeteringDocuments___Copy.ModelA, Energinet.FrontEndWeb.Client, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]].GetItemData(ModelA item)

   at Syncfusion.Blazor.DropDowns.SfDropDownList`2.<OnChangeEvent>d__493[[Energinet.FrontEndWeb.Client.BusinessAreas.Fskar.Pages.InterconnectorMeteringDocuments___Copy.ModelA, Energinet.FrontEndWeb.Client, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null],[Energinet.FrontEndWeb.Client.BusinessAreas.Fskar.Pages.InterconnectorMeteringDocuments___Copy.ModelA, Energinet.FrontEndWeb.Client, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]].MoveNext()

   at Syncfusion.Blazor.DropDowns.SfDropDownList`2.<FocusOutHandler>d__453[[Energinet.FrontEndWeb.Client.BusinessAreas.Fskar.Pages.InterconnectorMeteringDocuments___Copy.ModelA, Energinet.FrontEndWeb.Client, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null],[Energinet.FrontEndWeb.Client.BusinessAreas.Fskar.Pages.InterconnectorMeteringDocuments___Copy.ModelA, Energinet.FrontEndWeb.Client, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]].MoveNext()

   at Microsoft.AspNetCore.Components.ComponentBase.CallStateHasChangedOnAsyncCompletion(Task task)

   at Microsoft.AspNetCore.Components.RenderTree.Renderer.GetErrorHandledTask(Task taskToHandle, ComponentState owningComponentState)


4 Replies

UD UdhayaKumar Duraisamy Syncfusion Team May 17, 2022 06:35 PM UTC

Hi Christian,


We suggest you use TValue as string instead of object binding in your scenario. Please refer to the below code snippet and documentation for reference.

<SfDropDownList

                TItem="ModelA"

                TValue="string"

                DataSource="@Test">

    <DropDownListFieldSettings Text="TextA" Value="TextA" />

</SfDropDownList>

Documentation : https://blazor.syncfusion.com/documentation/dropdown-list/data-binding


Regards,

Udhaya Kumar D



CP Christian Palkowski Koch May 18, 2022 06:12 AM UTC

Alright i will rewrite my solution to use something similar. I hope you will consider fixing this bug anyway. 


Kind reagards.



UD UdhayaKumar Duraisamy Syncfusion Team May 19, 2022 08:14 AM UTC

Hi Christian,


TValue refers to the generic type, we can provide any applicable types to it respective to the Value field mapped to the component. So, it’s not a bug.


Regards,

Udhaya Kumar D



PI POL IT February 4, 2023 10:49 PM UTC

I suggest taking a look at this again. It sucks that I'm not able to put proxy objects in place of the target object.


Loader.
Up arrow icon