JeremyLikness/SqliteWasmHelper

Errors when deployed to Azure

DougBowen72 opened this issue · 1 comments

This works great when running from debug but when I deploy to Azure I get the exception below when creating the context from the factory. My context only has one simple entity with no date fields. Any way around this?

Microsoft.AspNetCore.Components.WebAssembly.Rendering.WebAssemblyRenderer[100]
Unhandled exception rendering component: Could not find method 'AddYears' on type 'System.DateOnly'
System.InvalidOperationException: Could not find method 'AddYears' on type 'System.DateOnly'

...

at SqliteWasmHelper.SqliteWasmDbContextFactory1[[EPOD_POC.Client.BrowserData.RouteContext, EPOD_POC.Client, Version=1.0.0.34966, Culture=neutral, PublicKeyToken=null]].GetFilename()
at SqliteWasmHelper.SqliteWasmDbContextFactory1.d__19[[EPOD_POC.Client.BrowserData.RouteContext, EPOD_POC.Client, Version=1.0.0.34966, Culture=neutral, PublicKeyToken=null]].MoveNext()
at SqliteWasmHelper.SqliteWasmDbContextFactory1.d__17[[EPOD_POC.Client.BrowserData.RouteContext, EPOD_POC.Client, Version=1.0.0.34966, Culture=neutral, PublicKeyToken=null]].MoveNext()
at SqliteWasmHelper.SqliteWasmDbContextFactory1.d__14[[EPOD_POC.Client.BrowserData.RouteContext, EPOD_POC.Client, Version=1.0.0.34966, Culture=neutral, PublicKeyToken=null]].MoveNext()
at EPOD_POC.Client.Pages.Home.CallSqlite()
at EPOD_POC.Client.Pages.Home.b__35_4(MouseEventArgs e)

Entity:

    public class TestEntity
    {
        public int Id { get; set; }
        public string NothingButAString { get; set; }
    }

Context:

public class RouteContext : DbContext
    {
        public RouteContext(DbContextOptions<RouteContext> opts) : base(opts)
        {

        }

        public DbSet<TestEntity> TestEntities { get; set; }
    }

Program.cs
builder.Services.AddSqliteWasmDbContextFactory<RouteContext>(opts => opts.UseSqlite("Data Source=Route.sqlite3"));

Component code behind (note I get the exception when only creating the context):

      [Inject] private ISqliteWasmDbContextFactory<RouteContext> _dbFactory { get; set; }

        protected async Task CallSqlite()
        {
            using var ctx = await _dbFactory.CreateDbContextAsync();
        }

This is a Microsoft issue and here's the workaround:

Add this to your App.razor or wherever you like:

@code{
///


/// FIXME: This is required for EF Core 6.0 as it is not compatible with trimming.
///

[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)]
private static Type _keepDateOnly = typeof(DateOnly);
}

Based on this issue:
dotnet/efcore#26860