Open kovlevi opened 2 years ago
Perhaps the problem is this, but I don't know the reason and it's fix. Please help me!
These are the pictures about the problem:
(I'm using init on a property)
I'm not sure about the entity error. Is it within C# Shell only? As in not when run as an independent app? The initializer error is the property "init", I think. I'll add this as a workaround for now. You can try it too.
And what about the first screenshot problem: the type initalizer 'Microsoft.EntityFrameworkCore.Internal.CoreStrings' threw exception(this happens only in builded apk, about entity error because of this error can't say anything if that would work in the builded(standalone) apk)? Do you have any idea about that why it happens or how can I solve it?
Maybe it is bundling a newer version of EntityFrameworkCore instead of the embedded one? I'll check. For now the app supports only 2.2.
No, just checked. It bundles into the APK what it is using - v2.2.
Yeah, I know and I have that 2.2.0 nuget package:
Then perhaps storage permissions? What is the root path?
FileSystem.AppDataDirectory - from xamarin essentials, this is where it creates the database(db3) file and I have storage permissions
Then the problem isn't path or permissions.
the type initalizer 'Microsoft.EntityFrameworkCore.Internal.CoreStrings' threw exception - this is the exception that it throws/shows
Well, the exception makes some sense now. Notice the missing native library in the APK? I'll fix that tomorrow.
Yeah, I see that your test app didn't generated that selected file. Thank you, I'm waiting for the update then
It looks like an issue in the dependency resolver. In case I don't manage to fix it tomorrow then manually referencing this library should do it.
Tried it, but it still throws the same exception
Maybe there is something else too. But make sure the lib is actually in APK.
Yeah, I see it inside(I renamed .apk to .zip to see it):
Ok, at least that works. I will look over the dependency resolver tomorrow. Maybe the wrong framework version DLL for something is being embedded.
All right. Anyway thanks for your help
I think I found the problem. Look for this file(this path was in innerexception message):
I don't see this file
It was mainly the dependency resolvers losing the scent. Should be working as expected in the next update.
When will you release the next update?
Probably tomorrow. I need to make sure nothing was broken by this change.
All right, thank you for your help
Updated C# Shell, but the same exception still throws and that assemblies/Microsoft.EntityFrameworkCore.resources.dll still not generated
Yes, I can see the error for the first time on my phone. I'll test an idea on how to fix it.
That exception is fixed with the latest update. But now this is the new Exception it throws:
This is my test code by the way:
using System; using System.IO; using Xamarin.Forms; using Microsoft.EntityFrameworkCore.Sqlite; using Microsoft.EntityFrameworkCore; using System.ComponentModel.DataAnnotations.Schema; using System.ComponentModel.DataAnnotations; using Xamarin.Essentials;
namespace EfTest { public partial class App : Application { public App() { InitializeComponent(); MainPage = new MainPage(); try { PersonDbContext context = new PersonDbContext(); Show("ok"); } catch(Exception ex) { Show(ex.Message); } }
async void Show(string s)
{
await App.Current.MainPage.DisplayAlert("",s,"OK");
}
}
class Person
{
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public long Id{get;set;}
public string Name{get;set;}
}
class PersonDbContext : DbContext
{
public DbSet<Person> People{get;set;}
public PersonDbContext()
{
Database.EnsureCreated();
}
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder.UseSqlite("Filename=/storage/emulated/0/data.db3");
}
}
}
Yeah, I have it too. Appears to happen every time EntityFrameworkCore wants to throw an Exception or log anything. Not sure what the root cause is. This might take longer to fix than expected.
All right then I will wait for the fix, hope you can fix all ef core bugs
It seems to be working now. Thank you very much for your help.
I just builded an apk (xamarin forms) with ef core and it throw the foolowing exception:![Screenshot_20220508_160544_com companyname gothamstrategy](https://user-images.githubusercontent.com/90194413/167300078-2bfae0fc-f7d7-4973-9e66-be991aa7807d.jpg)
The code within my db context:
public GothamDbContext() {
This happens in debug with seeding(hasdata in Onmodelcreating, but I think it's not important) even if I uncomment Database.EnsureDeleted():