Skip to content

Unexpected EndArray token when adding to a table #87

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
Ard2025 opened this issue May 16, 2025 · 3 comments
Open

Unexpected EndArray token when adding to a table #87

Ard2025 opened this issue May 16, 2025 · 3 comments
Assignees
Labels
bug Something isn't working

Comments

@Ard2025
Copy link

Ard2025 commented May 16, 2025

When adding data to the magicdb the token endarray is unexpected. To demonstrate i have minimized my application into a demo. in here adding to the player database does work, but not for the event and game tables. The demo code can be found at https://github.com/Ard2025/MagicIssue-endarray-token. The following error does appear.

crit: Microsoft.AspNetCore.Components.WebAssembly.Rendering.WebAssemblyRenderer[100]
      Unhandled exception rendering component: Unexpected JSON token: EndArray when deserializing JsonElement.
System.Text.Json.JsonException: Unexpected JSON token: EndArray when deserializing JsonElement.
   at Magic.IndexedDb.Models.MagicContractResolver`1[[System.Text.Json.JsonElement, System.Text.Json, Version=9.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51]].Read(Utf8JsonReader& reader, Type typeToConvert, JsonSerializerOptions options)
   at System.Text.Json.Serialization.JsonConverter`1[[System.Text.Json.JsonElement, System.Text.Json, Version=9.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51]].TryRead(Utf8JsonReader& reader, Type typeToConvert, JsonSerializerOptions options, ReadStack& state, JsonElement& value, Boolean& isPopulatedValue)
   at System.Text.Json.Serialization.JsonConverter`1[[System.Text.Json.JsonElement, System.Text.Json, Version=9.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51]].ReadCore(Utf8JsonReader& reader, JsonElement& value, JsonSerializerOptions options, ReadStack& state)
   at System.Text.Json.Serialization.Metadata.JsonTypeInfo`1[[System.Text.Json.JsonElement, System.Text.Json, Version=9.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51]].Deserialize(Utf8JsonReader& reader, ReadStack& state)
   at System.Text.Json.JsonSerializer.ReadFromSpan[JsonElement](ReadOnlySpan`1 utf8Json, JsonTypeInfo`1 jsonTypeInfo, Nullable`1 actualByteCount)
   at System.Text.Json.JsonSerializer.ReadFromSpan[JsonElement](ReadOnlySpan`1 json, JsonTypeInfo`1 jsonTypeInfo)
   at System.Text.Json.JsonSerializer.Deserialize[JsonElement](String json, JsonSerializerOptions options)
   at Magic.IndexedDb.Helpers.MagicSerializationHelper.DeserializeObject[JsonElement](String json, MagicJsonSerializationSettings settings)
   at Magic.IndexedDb.Extensions.MagicJsInvoke.<TrueMagicStreamJsAsync>d__10`1[[System.Text.Json.JsonElement, System.Text.Json, Version=9.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51]].MoveNext()
   at Magic.IndexedDb.Extensions.MagicJsInvoke.<TrueMagicStreamJsAsync>d__10`1[[System.Text.Json.JsonElement, System.Text.Json, Version=9.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51]].MoveNext()
   at Magic.IndexedDb.Extensions.MagicJsInvoke.<MagicStreamJsAsync>d__9`1[[System.Text.Json.JsonElement, System.Text.Json, Version=9.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51]].MoveNext()
   at Magic.IndexedDb.Extensions.MagicJsInvoke.<CallJsAsync>d__3`1[[System.Text.Json.JsonElement, System.Text.Json, Version=9.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51]].MoveNext()
   at Magic.IndexedDb.IndexedDbManager.<AddAsync>d__7`2[[Application.Models.Game, Application, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null],[System.Text.Json.JsonElement, System.Text.Json, Version=9.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51]].MoveNext()
   at Magic.IndexedDb.MagicQuery`1.<AddAsync>d__49[[Application.Models.Game, Application, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]].MoveNext()
   at Application.Pages.Home.TestGame() in C:\Users\ardva\source\repos\Ard2025\magicIssue\Application\Pages\Home.razor.cs:line 53
   at Application.Pages.Home.<BuildRenderTree>b__4_3() in C:\Users\ardva\source\repos\Ard2025\magicIssue\Application\Pages\Home.razor:line 24
   at Microsoft.AspNetCore.Components.ComponentBase.CallStateHasChangedOnAsyncCompletion(Task task)
   at Microsoft.AspNetCore.Components.RenderTree.Renderer.GetErrorHandledTask(Task taskToHandle, ComponentState owningComponentState)
@magiccodingman magiccodingman self-assigned this May 17, 2025
@magiccodingman magiccodingman added the bug Something isn't working label May 17, 2025
@magiccodingman
Copy link
Owner

Thank you for the detailed bug report! I've noted this as a bug and will look into the issue.

@magiccodingman
Copy link
Owner

@Ard2025 Before I got off for the night, I was just taking a quick glance. I didn't see any dynamic objects so I don't think this is the issue, but was just verifying it's not related too:
#84

Though I did also see that in "Game" there's "Result" which looks like an enum and/or a record I believe. I wonder if that's causing an issue. I will look into it this weekend as this should be a minor problem to resolve.

@Ard2025
Copy link
Author

Ard2025 commented May 22, 2025

#89 Should solve this issue. I am not sure why this works tho. I saw in other projects where a custom resolver was used that an break statement was used when an endarray token was encountered. This attempt seems to work. I have put it into a seperate statement because combining it with the top statement wasn't working for some reason, maybe that was just om my laptop.

I also think #84 is not related to this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants