rungwiroon / BlazorGoogleMaps

Blazor interop for GoogleMap library
MIT License
319 stars 102 forks source link

Using InteropObject.Data.SetStyle with call-back Func<Feature, StyleOptions> results in Newtonsoft.Json.JsonSerializationException #249

Closed tombrewer-onwave closed 1 year ago

tombrewer-onwave commented 1 year ago

When using the call-back (Func) functionality to vary the style options (based on feature properties) it attempts to serialize the Func and fails with a Newtonsoft.Json.JsonSerializationException: 'Self referencing loop detected for property 'module' with type 'System.Reflection.RuntimeModule'. Path 'method.module.assembly.entryPoint'.'

For example if you add a line to MapDataPage.razor in the server-side examples at the bottom of GetMapDataFeature() after the line 'await _map1.InteropObject.Data.AddGeoJson(rootFeature);' the exception is thrown when you run and click Get MapData (Feature).

await _map1.InteropObject.Data.SetStyle(new Func<Feature, StyleOptions>((feat) => { return new StyleOptions { StrokeColor = "blue", StrokeWeight = 2, FillColor = "magenta", FillOpacity = 0.3f }; })); Code

Error

valentasm1 commented 1 year ago

I this case i decided to migrate to system.text.json from json.net. I think i will be done till next sunday. Here is branch with most of changes are done. I started with marker testing/fixing and then move to other parts. When changed done i will take a look at your issue.

https://github.com/rungwiroon/BlazorGoogleMaps/tree/system.text.json_migration

tombrewer-onwave commented 1 year ago

Ok - I can't get that branch to build at the moment for the server side demo, but let me know if you want me to try or test anything out.

valentasm1 commented 1 year ago

Thank you for your help. I lost patience when when everything started to show errors :). Just left till next weekend. Marker demo is working so i need to added remaining attributes for rest of the project. Will let you know.

valentasm1 commented 1 year ago

Migration done. I am not sure if this functionality even posible out of the box. Do you have pure js example?