Crash when source chnaged and includes NaN values in SfGrid

Hi
I am not sure if this is a bug or not so I am posting this here and not in the bug tracker:
When using `SfGrid` to show a list of values which includes NaN values it's working fine,
however when the source is changing (i.e just copying it is enough: `Data = new List(Data);`)
it shows this error:
crit: Microsoft.AspNetCore.Components.WebAssembly.Rendering.WebAssemblyRenderer[100]
Unhandled exception rendering component: .NET number values such as positive and negative infinity cannot be written as valid JSON.
System.ArgumentException: .NET number values such as positive and negative infinity cannot be written as valid JSON.
at System.Text.Json.ThrowHelper.ThrowArgumentException_ValueNotSupported () <0x686d780 + 0x0000c> in :0
at System.Text.Json.JsonWriterHelper.ValidateSingle (System.Single value) <0x686d5b0 + 0x0001c> in :0
at System.Text.Json.Utf8JsonWriter.WriteNumberValue (System.Single value) <0x686d4a8 + 0x00004> in :0
at System.Text.Json.Serialization.Converters.JsonConverterSingle.Write (System.Text.Json.Utf8JsonWriter writer, System.Single value, System.Text.Json.JsonSerializerOptions options) <0x686d2e8 + 0x0000c> in :0
at System.Text.Json.JsonPropertyInfoNotNullable`4[TClass,TDeclaredProperty,TRuntimeProperty,TConverter].OnWrite (System.Text.Json.WriteStackFrame& current, System.Text.Json.Utf8JsonWriter writer) <0x686cfb8 + 0x000f4> in :0
at System.Text.Json.JsonPropertyInfo.Write (System.Text.Json.WriteStack& state, System.Text.Json.Utf8JsonWriter writer) <0x3cb4970 + 0x0005e> in :0
at System.Text.Json.JsonSerializer.HandleObject (System.Text.Json.JsonPropertyInfo jsonPropertyInfo, System.Text.Json.JsonSerializerOptions options, System.Text.Json.Utf8JsonWriter writer, System.Text.Json.WriteStack& state) <0x3cb45f0 + 0x000ae> in :0
at System.Text.Json.JsonSerializer.WriteObject (System.Text.Json.JsonSerializerOptions options, System.Text.Json.Utf8JsonWriter writer, System.Text.Json.WriteStack& state) <0x3cb41c8 + 0x000d4> in :0
at System.Text.Json.JsonSerializer.Write (System.Text.Json.Utf8JsonWriter writer, System.Int32 originalWriterDepth, System.Int32 flushThreshold, System.Text.Json.JsonSerializerOptions options, System.Text.Json.WriteStack& state) <0x3b8a940 + 0x000ee> in :0
at System.Text.Json.JsonSerializer.WriteCore (System.Text.Json.Utf8JsonWriter writer, System.Object value, System.Type type, System.Text.Json.JsonSerializerOptions options) <0x3973898 + 0x00084> in :0
at System.Text.Json.JsonSerializer.WriteCore (System.Text.Json.PooledByteBufferWriter output, System.Object value, System.Type type, System.Text.Json.JsonSerializerOptions options) <0x3976bf0 + 0x00040> in :0
at System.Text.Json.JsonSerializer.WriteCoreString (System.Object value, System.Type type, System.Text.Json.JsonSerializerOptions options) <0x39767c8 + 0x0003e> in :0
at System.Text.Json.JsonSerializer.Serialize[TValue] (TValue value, System.Text.Json.JsonSerializerOptions options) <0x684f0e0 + 0x0000c> in :0
at Syncfusion.Blazor.Internal.SfBaseUtils.Equals[T] (T oldValue, T newValue) <0x684efd0 + 0x00088> in :0
at Syncfusion.Blazor.SfDataBoundComponent.UpdateProperty[T] (System.String propertyName, T publicValue, T privateValue, System.Object eventCallback, System.Linq.Expressions.Expression`1[TDelegate] expression) <0x650b900 + 0x000d6> in :0
at Syncfusion.Blazor.Grids.SfGrid`1[TValue].OnHybridParametersSet () <0x650e880 + 0x01510> in :0
at Syncfusion.Blazor.Grids.SfGrid`1[TValue].OnParametersSetAsync () <0x64bfe38 + 0x001e8> in :0
at Microsoft.AspNetCore.Components.ComponentBase.CallStateHasChangedOnAsyncCompletion (System.Threading.Tasks.Task task) <0x3e0f4d0 + 0x000da> in :0
I am using the latest version:18.3.0.53
Sample code to reproduce the error:

@code {
[Parameter]
public List CalculatedData { get; set; }
public List Data = new List();
private SfGrid Grid;
protected void Refresh()
{
Data.Add(new FieldAverage() { Average = float.NaN } );
Grid.Refresh();
Data = new List(Data);
Grid.Refresh(); //Will crash here because of the previous line
}

public class FieldAverage
{
public float Average { get; set; }
}
}

5 Replies 1 reply marked as answer

NI Nimrod December 12, 2020 08:21 PM UTC

Sorry for the bad formatting, edit button seems to be broken and the is no formatting to past a code here(!?!)
Full code:
 
       
           
                
           
           
              
           
       
   

   
@code {
    [Parameter]
    public List CalculatedData { get; set; }
    public List Data = new List();
    private SfGrid Grid;

    protected void Refresh()
    {
        Console.WriteLine("VER 5");
        base.OnInitialized();
        Data.Add(new FieldAverage() { Average = float.NaN } );
        Grid.Refresh();
        Data = new List(Data);
        Grid.Refresh();
    }
 public class FieldAverage
    {
        public float Average { get; set; }
    }


}


NI Nimrod December 12, 2020 08:24 PM UTC

<SfGrid @ref="Grid" DataSource="@Data" Width="600">
        <GridColumns>
            <GridColumn HeaderText="Name" Width="400">
                
            </GridColumn>
            <GridColumn Field="@nameof(FieldAverage.Average)" HeaderText="Avarge/Success rate" Width="150">
              
            </GridColumn>
        </GridColumns>
    </SfGrid>

    <SfButton OnClick="Refresh"></SfButton>
</div>
@code {
    [Parameter]
    public List<FieldAverage> CalculatedData { get; set; }
    public List<FieldAverage> Data = new List<FieldAverage>();
    private SfGrid<FieldAverage> Grid;

    protected void Refresh()
    {
        Console.WriteLine("VER 5");
        base.OnInitialized();
        Data.Add(new FieldAverage() { Average = float.NaN } );
        Grid.Refresh();
        Data = new List<FieldAverage>(Data);
        Grid.Refresh();
    }
}


RS Renjith Singh Rajendran Syncfusion Team December 23, 2020 11:30 AM UTC

Hi Nimrod, 

Greetings from Syncfusion support. 

We have confirmed this as a bug and logged a defect report Exception is Thrown When we using NaN value in float typed Grid columnfor the same. Thank you for taking the time to report this issue and helping us improve our product. At Syncfusion, we are committed to fixing all validated defects (subject to technological feasibility and Product Development Life Cycle) and including the defect fix in our upcoming bi-weekly release which is expected to be rolled out by the mid of January 2021.  
    
You can now track the current status of your request, review the proposed resolution timeline, and contact us for any further inquiries through this link.     
     
Regards, 
Renjith R 




NI Nimrod February 16, 2021 09:09 AM UTC

Hi, I am facing the issue in another place in my code, is there going to be a fix soon?


RS Renjith Singh Rajendran Syncfusion Team February 18, 2021 11:33 AM UTC

Hi Nimrod, 

We are glad to announce that our Blazor Weekly patch release (v18.4.0.43) has been rolled out successfully and we have fixed this issue “Exception is Thrown When we using NaN value in float typed Grid column” in our latest version releases. So kindly update your NuGet (Syncfusion.Blazor) to our latest versions to resolve the reported issue.   

Please find the Nuget package from below  
 
We thank you for your support and appreciate your patience in waiting for this release. Please get back to us if you need any further assistance.   

Regards, 
Renjith R 


Marked as answer
Loader.
Up arrow icon