Closed MartinLeist closed 2 years ago
@MartinLeist I'm not sure that you need this:
SQLitePCL.Batteries_V2.Init();
SQLitePCL.raw.sqlite3_config(2 /*SQLITE_CONFIG_MULTITHREAD*/);
Typically the way to use SQLite with EFCore is through one direct reference to the Microsoft.EntityFrameworkCore.Sqlite
package. This automatically brings in a native SQLite DLL to use. Have you tried doing this?
/cc @bricelam
@ajcvickers I'm not sure why I added the first thing in the first place. It's been there for a year now. The second line was me hoping to counter the "Database is locked" issues... unfortunatly without success.
Removing both lines did unfortunatly not help.
What was strange was, that updating to EFCore 3 not always works the same for me. This time I had to add several nuggets (like Remotion.Linq, System.Interactive.Async or Microsoft.EntityFrameworkCore) and then got a lot of errors because WHERE was not unique between IEnumerableAsync and IQueryable. I reverted again, updated to EFCore 3 again and this time I didn't need the additional nugets, but I run into the vtable issue again.
I also get a Linker Error about a missing method
XALNK7000: Mono.Linker.MarkException: Error processing method: 'TProperty System.Text.Json.ReflectionMemberAccessor/<>c__DisplayClass14_0`2::<CreateStructPropertyGetter>b__0(System.Object)' in assembly: 'System.Text.Json.dll' ---> Mono.Cecil.ResolutionException: Failed to resolve !!0& System.Runtime.CompilerServices.Unsafe::Unbox(System.Object)
bei Mono.Linker.Steps.MarkStep.HandleUnresolvedMethod(MethodReference reference)
bei Mono.Linker.Steps.MarkStep.MarkMethod(MethodReference reference)
bei Mono.Linker.Steps.MarkStep.MarkInstruction(Instruction instruction)
bei Mono.Linker.Steps.MarkStep.MarkMethodBody(MethodBody body)
bei Mono.Linker.Steps.MarkStep.ProcessMethod(MethodDefinition method)
bei Mono.Linker.Steps.MarkStep.ProcessQueue()
--- Ende der internen Ausnahmestapelüberwachung ---
bei Mono.Linker.Steps.MarkStep.ProcessQueue()
bei Mono.Linker.Steps.MarkStep.ProcessPrimaryQueue()
bei Mono.Linker.Steps.MarkStep.Process()
bei Mono.Linker.Steps.MarkStep.Process(LinkContext context)
bei MonoDroid.Tuner.MonoDroidMarkStep.Process(LinkContext context)
bei Mono.Linker.Pipeline.ProcessStep(LinkContext context, IStep step)
bei Mono.Linker.Pipeline.Process(LinkContext context)
bei MonoDroid.Tuner.Linker.Process(LinkerOptions options, ILogger logger, LinkContext& context)
bei Xamarin.Android.Tasks.LinkAssemblies.Execute(DirectoryAssemblyResolver res)
bei Xamarin.Android.Tasks.LinkAssemblies.RunTask()
bei Xamarin.Android.Tasks.AndroidTask.Execute()
Deactivating the linker solves this of course, but I didn't run into that issue before updating to EFCore 3. I'm not sure if those issues are connected.
You have to call SQLitePCL.Batteries_V2.Init()
on Xamarin.iOS because we can't Assembly.Load there. I haven't heard of anyone needing to call it on Android. Sounds like you're hitting some Xamarin.Android bugs. Your csproj file doesn't specify <AndroidLinkMode>Full</AndroidLinkMode>
does it?
@bricelam Should I move that call then into the ios code or can it stay in the initialization code for the database?
The linker is deactivated and I controlled the csproj file and it also only contains <AndroidLinkMode>None</AndroidLinkMode>
I tried to start the project with other OS. iOS tells me it is unable to resolve "System.Diagnostics.PerformanceCounter" reference from "System, Version=4.0.0.0"... This has also not occured before I updated EFCore. I haven't found much helpful results googling for this error either. Disabling the linker does not work here because then the result is too large.
UWP can be started without an error.
You can leave Batteries.Init code in everywhere--it won't do any harm. We might need a project to dig into this. Also, are you using the latest Xamarin tools?
@bricelam I keep my Visual Studio up to date (currently 16.4.5) and installed the Android 10 SDK. I try to keep everything as up to date as possible. Currently I can't update Xamarin.Forms because of a bug in combination with Syncfusion. At the moment it is on 4.3.0.991211
Am I missing something I should be updating?
@marek-safar This looks like a xamarin-android issue. Is it something you have seen before?
This is most likely caused by missing assembly reference which Xamarin tools need to pass to IL Linker. Please report this issue to https://github.com/xamarin/xamarin-android if there is repro available.
Thanks @marek-safar.
@MartinLeist If you could put together a repro project and file an issue against https://github.com/xamarin/xamarin-android that would be great.
Hello all together. I'm affected by this issue in Xamarin.Forms-Android too (Xamarin.Forms-iOS and UWP not testet yet). I'm using Akavache.nuget as storage in my shared project, and want to replace it with EntityFrameWorkCore.SQLite. So this issue is a real show stopper for me. I can't run my app anymore.
Does not help: SQLitePCL.Batteries_V2.Init(); SQLitePCL.raw.sqlite3_config(2 /SQLITE_CONFIG_MULTITHREAD/); SQLitePCL.raw.FreezeProvider();
Is there any workaround? Thanks in advance and best regards
Error message is:
System.TypeLoadException: 'Parent class vtable failed to initialize, due to: VTable setup of type Microsoft.EntityFrameworkCore.DbContext failed
assembly: Microsoft.EntityFrameworkCore.dll type:DbContext member:(null)
at System.Runtime.CompilerServices.AsyncVoidMethodBuilder.Start[TStateMachine] (TStateMachine& stateMachine) [0x0002c] in /Users/builder/jenkins/workspace/archive-mono/2019-08/android/release/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/AsyncMethodBuilder.cs:84
I think I know what the problem is. Xamarin.Forms targets NETStandard 2.0 but EntityFrameworkCore targets NETStandard 2.1. What is confusing is, that in the Microsoft.EntityFrameworkCore.nuget under dependencies it says ".NETStandard,Version=v2.0", but in the documentation it says it depends on v2.1 (see link at the bottom)
So downgrading all installed EntityFrameworkCore nuget-packages to v.2.2.6 resolves the vtable issue.
https://docs.microsoft.com/de-de/ef/core/what-is-new/ef-core-3.0/breaking-changes#netstandard21
@mrtnsys EF Core 3.1 supports .net standard 2.0!
Thank you Erik, yes in the link above I found a note "EF Core 3.1 targets .NET Standard 2.0 again. This brings back support for .NET Framework." Sadly I can't use the Power Tools anymore, because I target EF Core 2.2.6 to get rid of the vtable exception, but Power Tools require EF Core 3. I liked to use the Migration Tool. So I'm trying to start the setup of the migration by commandline by now.
I am not sure the Power Tools require 3.x. why do you think that?
Cause when I try to use "Migration Tool" or "Add DbContext Model Diagram" I get an exception in Visual Studio Output: "System.IO.FileLoadException: Could not load file or assembly 'Microsoft.EntityFrameworkCore.Design, Version=3.0.0.0".
I'm referencing Microsoft.EntityFrameworkCore.Design but v.2.2.6. That's why I though it. Right?
In detail System.ArgumentException: Error: System.IO.FileLoadException: Could not load file or assembly 'Microsoft.EntityFrameworkCore.Design, Version=3.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'. The located assembly's manifest definition does not match the assembly reference. (0x80131040) File name: 'Microsoft.EntityFrameworkCore.Design, Version=3.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60' at ReverseEngineer20.EfCoreModelBuilder.BuildResult(String outputPath, Boolean generateDdl) at ReverseEngineer20.Program.Main(String[] args) in C:\Code\EFCorePowerTools\src\GUI\efpt\Program.cs:line 44
@MrtnSys That sounds like a bug or some other issue - please create an issue here https://github.com/ErikEJ/EFCorePowerTools/issues and share your .csproj file
Any news on this?` We also can't build anymore our iOS app, because of this error: MTOUCH : error MT2002: Failed to resolve "System.Diagnostics.PerformanceCounter" reference from "System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" [/Users/runner/runners/2.165.2/work/1/s/09_Mobile/*.iOS.csproj]
Before using EF Core 2.2.6 it was working.
@MartinLeist: could you resolve this issue somehow?
@MartinLeist, did you find a workaround for this issue?
@vecalion I updated again in june after not having time for it for a while. Back then I updated to EFCore 3.1.5 and I didn't get the VTable issue anymore. I looked into my commits from that time again, if I forgot something, but there is also no indication that I had to do much more. It was an update of pretty much every nuget of my app, so EFCore 3.1.5, EFCore.BulkExtensions 3.1.1 and Xamarin.Forms 4.7.0.968
@simader sorry for answering so late. If you still have that issue, I had the same one for a while. It indicates that somewhere a wrong dll was used (desktop instead of mobile). In my case the plugin i use (EFCore.BulkExtensions) changed from using System.Data.SqlClient to the new Microsoft.Data.SqlClient. After changing that the app worked again for me.
I tried updating my project from EFCore 2.2 to EFCore 3.1. I also configured all my GUIDs to continue writing into BLOB, because I want to wait if EFCore 5 might change this base type again.
Compiling the project is not an issue. I was also able to create a new Migration (that gave me all GUIDs as changes, even if they already were BLOBs, but I deleted that unnecessary change).
Unfortunatly I am not able to start the App on Android anymore. I always get the following Error in one of my first lines:
StackTrace
App.xaml.cs:34 calls my App init method. Within this method I create a first Context and therefore trigger the configuration.
My database initialization:
In my project I use a BaseContext, that derives from DbContext, to define everything that is the same on the Cloud (.netCore) and on the app. The App itself uses a LocalContext that derives from BaseContext and adds all the SQLite specific stuff and some definitions that are app specific.
I haven't found anything online about this issue, but some old incompatibility issues. I had an SQLite-PCL nuget installed, which I removed after reading it was incompatible and most likely not needed since I get the SQLite functions through EFCore.
I have deactivated the linker entirely, because I got another error I didn't put time into solving yet. I updated to the latest Xamarin.Forms and switched my projects to .netStandard 2.1.
Does anyone have an idea what the issue could be? Other than the definition of all GUIDs and the update to EFCore I did not change anything at first. I'm not sure if this is really a problem from EFCore or if something else is the core of the issue, but right now I have no idea where to look for a solution to this.
Further technical details
EF Core version: 3.1. Database provider: Microsoft.EntityFrameworkCore.Sqlite Target framework: .netStandard 2.0 / 2.1 , Xamarin.Forms 4.4 Operating system: Windows 10 Pro 18363 IDE: Visual Studio 2019 16.4.5
EDIT: Changed the database provider. I'm using Sqlite of course, not SqlServer