Crash when using Double? property in SQLIte in Blazor Wasm (.Net6)

Viewed 139

I'm using Blazor Wasm with a SQLite clientdatabase. Like here (https://github.com/dotnetnoobie/BlazorAppSqlite)

public DbSet<Test> Tests { get; set; } = default!;
.....
public class Test
{
    [Key]
    public int Id { get; set; }
    public double? NullableDoubleValue { get; set; }
}
......
var test = new Test();
test.Id = 1;
test.NullableDoubleValue = 1;

_appState.ClientSideDbContext.Tests.Add(test);
 await _appState.ClientSideDbContext.SaveChangesAsync();

When the last line is executed, the Blazor app wil crash. With this error in the log: /__w/1/s/src/mono/mono/mini/aot-runtime-wasm.c:113 /__w/1/s/src/mono/mono/mini/aot-runtime-wasm.c:113 Uncaught ExitStatus

What change do I have to make to use a (nullable) double?

1 Answers

The issue seems to come from using float or double. The fix has been merged and it will probably be released with dotnet 7 as mentioned in this issue.

Description

Seeing a bug when using SQLitePCL.Raw preview and also see the same bug in Steve Sandersons Blaze Orbital sample when using double/float in entity classes. Works fine with decimals! Tried with EF Core and SQLite-net.

As a workaround, you can use decimal instead of float or double and it will work just fine.

Related