Skip to content
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

Errors when deployed to Azure #10

Closed
DougBowen72 opened this issue Oct 14, 2022 · 1 comment
Closed

Errors when deployed to Azure #10

DougBowen72 opened this issue Oct 14, 2022 · 1 comment

Comments

@DougBowen72
Copy link

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();
        }

@DougBowen72
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant