I'm using a custom renderer on a WebView in my project, and I need it to be able to open popups, then I added JavaScriptCanOpenWindowsAutomatically settings to the constructor, but if I set it to true the app crashes at launch, here is my renderer:
[assembly: ExportRenderer(typeof(Xamarin.Forms.WebView), typeof(HybridWebViewRenderer))]
namespace ClotureSiadForms.Droid.Renderer
{
internal class HybridWebViewRenderer : WebViewRenderer
{
public HybridWebViewRenderer(Context context) : base(context)
{
}
protected override void OnElementChanged(ElementChangedEventArgs<Xamarin.Forms.WebView> e)
{
base.OnElementChanged(e);
if (Control != null)
{
Control.Settings.JavaScriptEnabled = true;
Control.Settings.DomStorageEnabled = true;
Control.Settings.SavePassword = true;
//Control.Settings.JavaScriptCanOpenWindowsAutomatically = true;
}
}
}
}
And the error:
10-19 19:05:55.667 HUAWEI RNE-L21 Error 24197 mono-rt [ERROR] FATAL UNHANDLED EXCEPTION: System.TypeInitializationException: The type initializer for 'Types' threw an exception. ---> System.EntryPointNotFoundException: java_interop_jvm_list assembly:<unknown assembly> type:<unknown type> member:(null)
at (wrapper managed-to-native) Java.Interop.NativeMethods.java_interop_jvm_list(intptr[],int,int&)
at Java.Interop.JniRuntime.GetCreatedJavaVMs (System.IntPtr[] handles, System.Int32 bufLen, System.Int32& nVMs) [0x00000] in <d12ba608ed5a4079a11cd8a7188dddcf>:0
at Java.Interop.JniRuntime.GetAvailableInvocationPointers () [0x00000] in <d12ba608ed5a4079a11cd8a7188dddcf>:0
at Java.Interop.JniRuntime.get_CurrentRuntime () [0x00095] in <d12ba608ed5a4079a11cd8a7188dddcf>:0
at Java.Interop.JniEnvironmentInfo..ctor () [0x00006] in <d12ba608ed5a4079a11cd8a7188dddcf>:0
at Java.Interop.JniEnvironment+<>c.<.cctor>b__35_0 () [0x00000] in <d12ba608ed5a4079a11cd8a7188dddcf>:0
at System.Threading.ThreadLocal`1[T].GetValueSlow () [0x00031] in <a790ddc2dda1484d9a4b87dd85c6ca47>:0
at System.Threading.ThreadLocal`1[T].get_Value () [0x0003e] in <a790ddc2dda1484d9a4b87dd85c6ca47>:0
at Java.Interop.JniEnvironment+Types.TryFindClass (System.String classname, System.Boolean throwOnError) [0x00014] in <d12ba608ed5a4079a11cd8a7188dddcf>:0
at Java.Interop.JniEnvironment+Types.FindClass (System.String classname) [0x00000] in <d12ba608ed5a4079a11cd8a7188dddcf>:0
at Java.Interop.JniType..ctor (System.String classname) [0x00006] in <d12ba608ed5a4079a11cd8a7188dddcf>:0
at Java.Interop.JniEnvironment+Types..cctor () [0x000d2] in <d12ba608ed5a4079a11cd8a7188dddcf>:0
--- End of inner exception stack trace ---
at Android.Runtime.JNIEnv.IsInstanceOf (System.IntPtr obj, System.IntPtr clazz) [0x0000e] in <ac4226d0aad24df781f4097e7b8b972f>:0
at Android.Runtime.JNIEnv.IsGCUserPeer (System.IntPtr value) [0x0000f] in <ac4226d0aad24df781f4097e7b8b972f>:0
Then, is there another way to make blank links open in the default browser ? Or to prevent this error ?
Related
I was using Plugin.FilePicker to pick files from the device. It was working fine on android version 11 and below. But on android version 12 and above, it is breaking with below exception:
Java.Lang.NullPointerException: uri
at Java.Interop.JniEnvironment+InstanceMethods.CallNonvirtualObjectMethod (Java.Interop.JniObjectReference instance, Java.Interop.JniObjectReference type, Java.Interop.JniMethodInfo method, Java.Interop.JniArgumentValue* args) [0x00088] in /Users/runner/work/1/s/xamarin-android/external/Java.Interop/src/Java.Interop/obj/Release/JniEnvironment.g.cs:11928
at Java.Interop.JniPeerMembers+JniInstanceMethods.InvokeNonvirtualObjectMethod (System.String encodedMember, Java.Interop.IJavaPeerable self, Java.Interop.JniArgumentValue* parameters) [0x0001e] in /Users/runner/work/1/s/xamarin-android/external/Java.Interop/src/Java.Interop/Java.Interop/JniPeerMembers.JniInstanceMethods_Invoke.cs:894
at Android.Content.ContentResolver.Query (Android.Net.Uri uri, System.String[] projection, System.String selection, System.String[] selectionArgs, System.String sortOrder) [0x000a0] in /Users/runner/work/1/s/xamarin-android/src/Mono.Android/obj/Release/monoandroid10/android-33/mcw/Android.Content.ContentResolver.cs:1456
at Plugin.FilePicker.IOUtil.GetDataColumn (Android.Content.Context context, Android.Net.Uri uri, System.String selection, System.String[] selectionArgs) [0x00013] in D:\a\1\s\src\Plugin.FilePicker\Android\IOUtil.android.cs:151
at Plugin.FilePicker.IOUtil.GetPath (Android.Content.Context context, Android.Net.Uri uri) [0x00167] in D:\a\1\s\src\Plugin.FilePicker\Android\IOUtil.android.cs:108
at Plugin.FilePicker.FilePickerActivity.OnActivityResult (System.Int32 requestCode, Android.App.Result resultCode, Android.Content.Intent data) [0x00039] in D:\a\1\s\src\Plugin.FilePicker\Android\FilePickerActivity.android.cs:151
--- End of stack trace from previous location where exception was thrown ---
at Plugin.FilePicker.FilePickerImplementation.PickFile (System.String[] allowedTypes) [0x00028] in D:\a\1\s\src\Plugin.FilePicker\Android\FilePickerImplementation.android.cs:60
at CatholicBrain.ConnectAppModule.CreateActivityPage.PickFile (System.Object sender, System.EventArgs args) [0x00075] in :0
--- End of managed Java.Lang.NullPointerException stack trace ---
java.lang.NullPointerException: uri
at java.util.Objects.requireNonNull(Objects.java:245)
at android.content.ContentResolver.query(ContentResolver.java:1225)
at android.content.ContentResolver.query(ContentResolver.java:1184)
at android.content.ContentResolver.query(ContentResolver.java:1140)
at crc64424a8adc5a1fbe28.FilePickerActivity.n_onActivityResult(Native Method)
at crc64424a8adc5a1fbe28.FilePickerActivity.onActivityResult(FilePickerActivity.java:48)
at android.app.Activity.dispatchActivityResult(Activity.java:8840)
at android.app.ActivityThread.deliverResults(ActivityThread.java:5694)
at android.app.ActivityThread.handleSendResult(ActivityThread.java:5740)
at android.app.servertransaction.ActivityResultItem.execute(ActivityResultItem.java:54)
at android.app.servertransaction.ActivityTransactionItem.execute(ActivityTransactionItem.java:45)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2458)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loopOnce(Looper.java:233)
at android.os.Looper.loop(Looper.java:334)
at android.app.ActivityThread.main(ActivityThread.java:8501)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:582)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1068)
I checked for any updates for Plugin.FilePicker and found that the package is deprecated. So I installed the Xamarin.Essentials package and updated codes for picking files. It is working fine on android version 12 and above.
Xamarin.Essentials.FileResult file = null;
file = await FilePicker.PickAsync();
if (file != null)
{
filename_label.IsVisible = true;
filename_label.Text = file.FileName;
upload_layout.IsVisible = true;
}
But when I try to upload the file using our REST API it fails with below exception:
System.IO.FileNotFoundException: hail-mary.pdf
File name: 'hail-mary.pdf' ---> Java.IO.FileNotFoundException: hail-mary.pdf
at Java.Interop.JniEnvironment+InstanceMethods.CallObjectMethod (Java.Interop.JniObjectReference instance, Java.Interop.JniMethodInfo method, Java.Interop.JniArgumentValue* args) [0x00068] in /Users/runner/work/1/s/xamarin-android/external/Java.Interop/src/Java.Interop/obj/Release/JniEnvironment.g.cs:11524
at Java.Interop.JniPeerMembers+JniInstanceMethods.InvokeAbstractObjectMethod (System.String encodedMember, Java.Interop.IJavaPeerable self, Java.Interop.JniArgumentValue* parameters) [0x0001e] in /Users/runner/work/1/s/xamarin-android/external/Java.Interop/src/Java.Interop/Java.Interop/JniPeerMembers.JniInstanceMethods_Invoke.cs:848
at Android.Content.Res.AssetManager.Open (System.String fileName) [0x0001f] in /Users/runner/work/1/s/xamarin-android/src/Mono.Android/obj/Release/monoandroid10/android-33/mcw/Android.Content.Res.AssetManager.cs:265
at Xamarin.Essentials.FileSystem.PlatformOpenAppPackageFileAsync (System.String filename) [0x0001d] in D:\a_work\1\s\Xamarin.Essentials\FileSystem\FileSystem.android.cs:48
--- End of managed Java.IO.FileNotFoundException stack trace ---
java.io.FileNotFoundException: hail-mary.pdf
at android.content.res.AssetManager.nativeOpenAsset(Native Method)
at android.content.res.AssetManager.open(AssetManager.java:893)
at android.content.res.AssetManager.open(AssetManager.java:870)
at crc64ee486da937c010f4.ButtonRenderer.n_onClick(Native Method)
at crc64ee486da937c010f4.ButtonRenderer.onClick(ButtonRenderer.java:107)
at android.view.View.performClick(View.java:7512)
at android.view.View.performClickInternal(View.java:7489)
at android.view.View.access$3700(View.java:857)
at android.view.View$PerformClick.run(View.java:29034)
at android.os.Handler.handleCallback(Handler.java:938)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loopOnce(Looper.java:233)
at android.os.Looper.loop(Looper.java:334)
at android.app.ActivityThread.main(ActivityThread.java:8501)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:582)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1068)
at Xamarin.Essentials.FileSystem.PlatformOpenAppPackageFileAsync (System.String filename) [0x00036] in D:\a_work\1\s\Xamarin.Essentials\FileSystem\FileSystem.android.cs:52
at Xamarin.Essentials.FileSystem.OpenAppPackageFileAsync (System.String filename) [0x00000] in D:\a_work\1\s\Xamarin.Essentials\FileSystem\FileSystem.shared.cs:16
at CatholicBrain.ConnectAppModule.CreateActivityPage.UploadFile (System.Object sender, System.EventArgs e) [0x00126] in <8fb254ba200e4d369cb3f96cc3e665ff>:0
Upload Code:
var content = new MultipartFormDataContent();
Stream stream = await FileSystem.OpenAppPackageFileAsync(file.FileName);
byte[] data;
using (MemoryStream ms = new MemoryStream())
{
stream.CopyTo(ms);
data = ms.ToArray();
ms.Dispose();
}
content.Add(new StreamContent(stream), "\"fileUpload\"", $"\"{file.FullPath}\"");
var httpClient = new HttpClient();
var response = await httpClient.PostAsync(new Uri(REST API Path), content);
file.FullPath is provided on the upload code but getting FileNotFoundException.
If you use FilePicker.PickAsync(); to get the file, you do not need to use Stream stream = await FileSystem.OpenAppPackageFileAsync(file.FullPath); to read it to stream.
Just use Stream stream = await file.OpenReadAsync(); directly, then you can get the stream.
enter image description hereThere's signature popup first time with none enter(signature stoke) close the popup by clicking on cancel button and once more reopening the popup and providing a input(stroke) once after stoke is completed variable is set to true
On onpropertychange throwing below excetion
System.ObjectDisposedException: 'Cannot access a disposed object.
Object name: 'AndroidX.AppCompat.Widget.AppCompatButton'.'
enter image description hereenter image description here
Stack Trace
at Java.Interop.JniPeerMembers.AssertSelf (Java.Interop.IJavaPeerable self) [0x00029] in :0
at Java.Interop.JniPeerMembers+JniInstanceMethods.InvokeVirtualBooleanMethod (System.String encodedMember, Java.Interop.IJavaPeerable self, Java.Interop.JniArgumentValue* parameters) [0x00000] in :0
at Android.Views.View.get_Enabled () [0x00000] in /Users/builder/azdo/work/1/s/xamarin-android/src/Mono.Android/obj/Release/monoandroid10/android-29/mcw/Android.Views.View.cs:6262
at XF.Material.Droid.Renderers.MaterialDrawableHelper.CreateStateListAnimator () [0x00000] in /Users/martijn/Documents/OpenSource/XF-Material-Library/XF.Material/Platforms/Android/Renderers/MaterialDrawableHelper.cs:291
at XF.Material.Droid.Renderers.MaterialDrawableHelper.UpdateElevation () [0x00008] in /Users/martijn/Documents/OpenSource/XF-Material-Library/XF.Material/Platforms/Android/Renderers/MaterialDrawableHelper.cs:286
at XF.Material.Droid.Renderers.MaterialDrawableHelper.BindableButton_PropertyChanged (System.Object sender, System.ComponentModel.PropertyChangedEventArgs e) [0x00029] in /Users/martijn/Documents/OpenSource/XF-Material-Library/XF.Material/Platforms/Android/Renderers/MaterialDrawableHelper.cs:110
at (wrapper delegate-invoke) .invoke_void_object_PropertyChangedEventArgs(object,System.ComponentModel.PropertyChangedEventArgs)
at Xamarin.Forms.BindableObject.OnPropertyChanged (System.String propertyName) [0x00000] in D:\a\1\s\Xamarin.Forms.Core\BindableObject.cs:266
at Xamarin.Forms.Element.OnPropertyChanged (System.String propertyName) [0x00000] in D:\a\1\s\Xamarin.Forms.Core\Element.cs:362
at XF.Material.Forms.UI.MaterialButton.OnPropertyChanged (System.String propertyName) [0x0001a] in /Users/martijn/Documents/OpenSource/XF-Material-Library/XF.Material/UI/MaterialButton.cs:108
at Xamarin.Forms.BindableObject.SetValueActual (Xamarin.Forms.BindableProperty property, Xamarin.Forms.BindableObject+BindablePropertyContext context, System.Object value, System.Boolean currentlyApplying, Xamarin.Forms.Internals.SetValueFlags attributes, System.Boolean silent) [0x00114] in D:\a\1\s\Xamarin.Forms.Core\BindableObject.cs:510
at Xamarin.Forms.BindableObject.SetValueCore (Xamarin.Forms.BindableProperty property, System.Object value, Xamarin.Forms.Internals.SetValueFlags attributes, Xamarin.Forms.BindableObject+SetValuePrivateFlags privateAttributes) [0x00173] in D:\a\1\s\Xamarin.Forms.Core\BindableObject.cs:446
at Xamarin.Forms.BindingExpression.ApplyCore (System.Object sourceObject, Xamarin.Forms.BindableObject target, Xamarin.Forms.BindableProperty property, System.Boolean fromTarget) [0x00226] in D:\a\1\s\Xamarin.Forms.Core\BindingExpression.cs:160
at Xamarin.Forms.BindingExpression.Apply (System.Boolean fromTarget) [0x0003e] in D:\a\1\s\Xamarin.Forms.Core\BindingExpression.cs:56
at Xamarin.Forms.BindingExpression+BindingExpressionPart.b__49_0 () [0x00000] in D:\a\1\s\Xamarin.Forms.Core\BindingExpression.cs:762
at Xamarin.Forms.BindingExpression+BindingExpressionPart.PropertyChanged (System.Object sender, System.ComponentModel.PropertyChangedEventArgs args) [0x000cb] in D:\a\1\s\Xamarin.Forms.Core\BindingExpression.cs:773
at Xamarin.Forms.BindingExpression+WeakPropertyChangedProxy.OnPropertyChanged (System.Object sender, System.ComponentModel.PropertyChangedEventArgs e) [0x00012] in D:\a\1\s\Xamarin.Forms.Core\BindingExpression.cs:666
at (wrapper delegate-invoke) .invoke_void_object_PropertyChangedEventArgs(object,System.ComponentModel.PropertyChangedEventArgs)
at XamarinUniversity.Infrastructure.SimpleViewModel.RaisePropertyChanged (System.String propertyName) [0x00012] in :0
at ICR_MobileApp.ViewModels.SignatureSectionViewModel.OnStrokeCompleted () [0x0001c] in C:\Users\supriya.mecharla\source\repos\ICR_MobileApp\ICR_MobileApp\ICR_MobileApp\ViewModels\SectionViewModels\SignatureSectionViewModel.cs:262
at ICR_MobileApp.ViewModels.SignatureSectionViewModel.<.ctor>b__50_6 () [0x00000] in C:\Users\supriya.mecharla\source\repos\ICR_MobileApp\ICR_MobileApp\ICR_MobileApp\ViewModels\SectionViewModels\SignatureSectionViewModel.cs:168
at Xamarin.Forms.Command+<>c__DisplayClass4_0.<.ctor>b__0 (System.Object o) [0x00000] in D:\a\1\s\Xamarin.Forms.Core\Command.cs:74
at Xamarin.Forms.Command.Execute (System.Object parameter) [0x00000] in D:\a\1\s\Xamarin.Forms.Core\Command.cs:112
at SignaturePad.Forms.SignaturePadCanvasView.OnStrokeCompleted () [0x00039] in :0
at SignaturePad.Forms.SignaturePadCanvasRenderer.OnStrokeCompleted (System.Object sender, System.EventArgs e) [0x0000a] in :0
at Xamarin.Controls.SignaturePadCanvasView.OnStrokeCompleted (System.Object sender, System.EventArgs e) [0x0000a] in <0c0873655a504a1796935fa2cfa62e06>:0
at Xamarin.Controls.InkPresenter.OnStrokeCompleted () [0x0000a] in <0c0873655a504a1796935fa2cfa62e06>:0
at Xamarin.Controls.InkPresenter.TouchesEnded (Android.Views.MotionEvent e) [0x0003c] in <0c0873655a504a1796935fa2cfa62e06>:0
at Xamarin.Controls.InkPresenter.OnTouchEvent (Android.Views.MotionEvent e) [0x0002e] in <0c0873655a504a1796935fa2cfa62e06>:0
at Android.Views.View.n_OnTouchEvent_Landroid_view_MotionEvent (System.IntPtr jnienv, System.IntPtr native__this, System.IntPtr native_e) [0x00010] in /Users/builder/azdo/_work/1/s/xamarin-android/src/Mono.Android/obj/Release/monoandroid10/android-29/mcw/Android.Views.View.cs:18286
at (wrapper dynamic-method) Android.Runtime.DynamicMethodNameCounter.35(intptr,intptr,intptr)
While using sfprogressbar we are getting an Appcenter Error.
ProgressBarBase.ApplyDrawableColor (Android.Graphics.Drawables.Drawable drawable, Android.Graphics.Color color, Android.Graphics.PorterDuff+Mode mode)
System.ObjectDisposedException: Cannot access a disposed object. Object name: 'Android.Graphics.Drawables.ScaleDrawable .
Why this error occurred and how to resolve this error.
Java.Interop
JniPeerMembers.AssertSelf (Java.Interop.IJavaPeerable self)
Java.Interop
JniPeerMembers+JniInstanceMethods.InvokeVirtualVoidMethod (System.String encodedMember, Java.Interop.IJavaPeerable self, Java.Interop.JniArgumentValue* parameters)
Android.Graphics.Drawables
Drawable.SetTint (System.Int32 tintColor)
Syncfusion.Android.ProgressBar
ProgressBarBase.ApplyDrawableColor (Android.Graphics.Drawables.Drawable drawable, Android.Graphics.Color color, Android.Graphics.PorterDuff+Mode mode)
Syncfusion.Android.ProgressBar
SfLinearProgressBar.SetProgressColor ()
Syncfusion.Android.ProgressBar
ProgressBarBase.set_ProgressColor (Android.Graphics.Color value)
Syncfusion.XForms.Android.ProgressBar
ProgressBarUtility.OnLinearBarPropertyChanged (Syncfusion.Android.ProgressBar.SfLinearProgressBar native, Syncfusion.XForms.ProgressBar.SfLinearProgressBar control, System.String propertyName)
Syncfusion.Android.ProgressBar
SfLinearProgressBar.OnLinearProgressBarPropertiesChanged (System.Object sender, System.ComponentModel.PropertyChangedEventArgs e)
(wrapper delegate-invoke) <Module>.invoke_void_object_PropertyChangedEventArgs(object,System.ComponentModel.PropertyChangedEventArgs)
Xamarin.Forms
BindableObject.OnPropertyChanged (System.String propertyName)
Xamarin.Forms
Element.OnPropertyChanged (System.String propertyName)
Xamarin.Forms
BindableObject.SetValueActual (Xamarin.Forms.BindableProperty property, Xamarin.Forms.BindableObject+BindablePropertyContext context, System.Object value, System.Boolean currentlyApplying, Xamarin.Forms.Internals.SetValueFlags attributes, System.Boolean silent)
Xamarin.Forms
BindableObject.SetValueCore (Xamarin.Forms.BindableProperty property, System.Object value, Xamarin.Forms.Internals.SetValueFlags attributes, Xamarin.Forms.BindableObject+SetValuePrivateFlags privateAttributes)
Xamarin.Forms
BindingExpression.ApplyCore (System.Object sourceObject, Xamarin.Forms.BindableObject target, Xamarin.Forms.BindableProperty property, System.Boolean fromTarget)
Xamarin.Forms
BindingExpression.Apply (System.Boolean fromTarget)
Xamarin.Forms
BindingExpression+BindingExpressionPart.<PropertyChanged>b__49_0 ()
Xamarin.Forms
BindingExpression+BindingExpressionPart.PropertyChanged (System.Object sender, System.ComponentModel.PropertyChangedEventArgs args)
Xamarin.Forms
BindingExpression+WeakPropertyChangedProxy.OnPropertyChanged (System.Object sender, System.ComponentModel.PropertyChangedEventArgs e)
(wrapper delegate-invoke) <Module>.invoke_void_object_PropertyChangedEventArgs(object,System.ComponentModel.PropertyChangedEventArgs)
StackTrace:
NavigationRenderer+ParentingViewController.Dispose (System.Boolean disposing)
NSObject.Dispose ()
NavigationRenderer.Dispose (System.Boolean disposing)
NSObject.Dispose ()
DisposeHelpers.DisposeModalAndChildRenderers (Xamarin.Forms.Element view)
IDisposable.Dispose ()
FormsApplicationDelegate.UpdateMainPage ()
FormsApplicationDelegate.ApplicationOnPropertyChanged (System.Object sender, System.ComponentModel.PropertyChangedEventArgs args)
BindableObject.OnPropertyChanged (System.String propertyName)
Element.OnPropertyChanged (System.String propertyName)
Application.set_MainPage (Xamarin.Forms.Page value)
PageModelCoreMethods.SwitchOutRootNavigation (System.String navigationServiceName)
BasePageModel.<NavigateToLoginPage>b__74_0 () // I think the problem is in this method
NSAsyncActionDispatcher.Apply ()
(wrapper managed-to-native) UIKit.UIApplication.UIApplicationMain(int,string[],intptr,intptr)
UIApplication.Main (System.String[] args, System.IntPtr principal, System.IntPtr delegate)
UIApplication.Main (System.String[] args, System.String principalClassName, System.String delegateClassName)
Application.Main (System.String[] args)
This is the stack trace for a SIGABRT crash I'm getting in my iOS app using Xamarin.Forms 4.4.
I think the issue is coming from this method:
async protected virtual Task<bool> NavigateToLoginPage()
{
await LoginProvider.Clear();
Platform.BeginInvokeOnMainThread( () =>
{
CoreMethods.SwitchOutRootNavigation(CoreApp.LoginNavigationStack);
});
return true;
}
because it's the last method that was called before the crashing II'm assuming but I'm not sure how to fix it. I've looked at some solutions online like:
MonoTouch SIGSEGV crash using navigationcontroller and searchdisplaycontroller and https://forums.xamarin.com/discussion/6546/finding-the-cause-of-sigsegv which I think are related, but they don't match my case exactly..
Does anybody know what to do about this?
Thanks!
I’m working on a Xamarin.Forms cross-platform App project and I’m willing to use EF Core on my models to enable code-first migrations on my future versions. I managed to generate an initialization migration by using an ad-hoc .Net Core app as I needed a runtime environment for this task (see further details at ngrumbine’s demo https://github.com/ngrumbine/EFDemo).
The problem is that when launching my solution on iOS and Android emulators, the application crashes when reaching the call to the EF Core migration application method (DatabaseFacade.Migrate : https://learn.microsoft.com/en-us/dotnet/api/microsoft.entityframeworkcore.relationaldatabasefacadeextensions.migrate?view=efcore-3.0)
It happens here:
using Microsoft.EntityFrameworkCore;
namespace EFCoreMigrationIssue.Persistence
{
public class EFCoreMigrationIssueDbContext : DbContext
{
private string _databasePath;
public EFCoreMigrationIssueDbContext(string databasePath)
{
_databasePath = databasePath;
Database.Migrate();
}
public DbSet<Foo> Foos { get; set; }
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder.UseSqlite($"Filename={_databasePath}");
}
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<Foo>().HasIndex(f => f.Uri)
.IsUnique(true);
}
}
}
I checked the _databasePath attribute, and it is correctly initialized. Moreover, when using the debugger, the call to OnConfiguring(...) passes successfully, and the failure comes from an unreachable code part.
This happens at the same stage on both iOS and Android platforms, but with quite different stacktraces (see the bottom of this post).
Concerning the context: the mainpage view constructor tries to load a list of items from the database repository, which triggers the failling call to the database contexts factory.
Mainpage view xaml.cs code:
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Windows.Input;
using EFCoreMigrationIssue.Persistence;
using Xamarin.Forms;
namespace EFCoreMigrationIssue
{
[DesignTimeVisible(false)]
public partial class MainPage : ContentPage
{
private FooRepository fooRepository;
public MainPage()
{
InitializeComponent();
fooRepository = new FooRepository();
RecordUri = new Command(() => AddFooToRepository(),
canExecute: () => !string.IsNullOrEmpty(Uri));
LoadFooList();
}
internal ObservableCollection<Foo> FooList { get; private set; }
internal ICommand RecordUri { get; private set; }
internal string Uri { get; set; }
private void LoadFooList()
{
FooList = new ObservableCollection<Foo>(fooRepository.GetAll());
}
private void AddFooToRepository()
{
var foo = new Foo(Uri);
fooRepository.Add(foo);
}
}
}
With my model Foo being :
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace EFCoreMigrationIssue.Persistence
{
[Table(nameof(Foo))]
public class Foo
{
public Foo(string uri)
{
Uri = uri;
}
[Key]
public int Id { get; set; }
public string Uri { get; set; }
}
}
And the FooRepository being :
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Xamarin.Essentials;
namespace EFCoreMigrationIssue.Persistence
{
public class FooRepository
{
public FooRepository()
{
}
public void Add(Foo item)
{
using var context = GetDbContext();
context.Foos.Add(item);
context.SaveChanges();
}
public IEnumerable<Foo> GetAll()
{
using var context = GetDbContext();
return context.Foos.ToList();
}
private EFCoreMigrationIssueDbContext GetDbContext()
{
return new EFCoreMigrationIssueDbContext(GetDbFilePath());
}
private string GetDbFilePath()
{
var filename = "database.db3";
return Path.Combine(FileSystem.AppDataDirectory, filename);
}
}
}
The initial migration to be applied (automatically generated):
// <auto-generated />
using EFCoreMigrationIssue.Persistence;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
namespace EFCoreMigrationIssue.Persistence.Migrations
{
[DbContext(typeof(EFCoreMigrationIssueDbContext))]
partial class EFCoreMigrationIssueDbContextModelSnapshot : ModelSnapshot
{
protected override void BuildModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "3.0.1");
modelBuilder.Entity("EFCoreMigrationIssue.Persistence.Foo", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<string>("Uri")
.HasColumnType("TEXT");
b.HasKey("Id");
b.HasIndex("Uri")
.IsUnique();
b.ToTable("Foo");
});
#pragma warning restore 612, 618
}
}
}
The complete source code of my crash-demo project can be cloned here : https://github.com/anucii/EFCoreMigrationIssue.git
Stacktrace on iOS:
System.NullReferenceException: Object reference not set to an instance
of an object at SQLitePCL.raw.sqlite3_open_v2 (SQLitePCL.utf8z
filename, SQLitePCL.sqlite3& db, System.Int32 flags, SQLitePCL.utf8z
vfs) [0x00000] in <20c60171f1e84dae90646bc69aa016a2>:0 at
SQLitePCL.raw.sqlite3_open_v2 (System.String filename,
SQLitePCL.sqlite3& db, System.Int32 flags, System.String vfs)
[0x0000e] in <20c60171f1e84dae90646bc69aa016a2>:0 at
Microsoft.Data.Sqlite.SqliteConnection.Open () [0x00122] in
<4595d52549d54c96abd42a829433f17f>:0 at
Microsoft.EntityFrameworkCore.Storage.RelationalConnection.OpenDbConnection
(System.Boolean errorsExpected) [0x00068] in
:0 at
Microsoft.EntityFrameworkCore.Storage.RelationalConnection.Open
(System.Boolean errorsExpected) [0x00042] in
:0 at
Microsoft.EntityFrameworkCore.Sqlite.Storage.Internal.SqliteDatabaseCreator.Exists
() [0x0000c] in :0 at
Microsoft.EntityFrameworkCore.Migrations.HistoryRepository.Exists ()
[0x0000b] in :0 at
Microsoft.EntityFrameworkCore.Migrations.Internal.Migrator.Migrate
(System.String targetMigration) [0x00012] in
:0 at
Microsoft.EntityFrameworkCore.RelationalDatabaseFacadeExtensions.Migrate
(Microsoft.EntityFrameworkCore.Infrastructure.DatabaseFacade
databaseFacade) [0x00010] in :0 at
EFCoreMigrationIssue.Persistence.EFCoreMigrationIssueDbContext..ctor
(System.String databasePath) [0x0000f] in /Users/dev3/Virtual
Machines.localized/shared/stackoverflow_samples/EFCoreMigrationIssue/EFCoreMigrationIssue.Persistence/EFCoreMigrationIssueDbContext.cs:13
at EFCoreMigrationIssue.Persistence.FooRepository.GetDbContext ()
[0x00001] in /Users/dev3/Virtual
Machines.localized/shared/stackoverflow_samples/EFCoreMigrationIssue/EFCoreMigrationIssue.Persistence/FooRepository.cs:32
at EFCoreMigrationIssue.Persistence.FooRepository.GetAll () [0x00001]
in /Users/dev3/Virtual
Machines.localized/shared/stackoverflow_samples/EFCoreMigrationIssue/EFCoreMigrationIssue.Persistence/FooRepository.cs:25
at EFCoreMigrationIssue.MainPage.LoadFooList () [0x00001] in
/Users/dev3/Virtual
Machines.localized/shared/stackoverflow_samples/EFCoreMigrationIssue/EFCoreMigrationIssue/MainPage.xaml.cs:36 at EFCoreMigrationIssue.MainPage..ctor () [0x0003e] in
/Users/dev3/Virtual
Machines.localized/shared/stackoverflow_samples/EFCoreMigrationIssue/EFCoreMigrationIssue/MainPage.xaml.cs:27 at EFCoreMigrationIssue.App..ctor () [0x0000f] in /Users/dev3/Virtual
Machines.localized/shared/stackoverflow_samples/EFCoreMigrationIssue/EFCoreMigrationIssue/App.xaml.cs:13
at EFCoreMigrationIssue.iOS.AppDelegate.FinishedLaunching
(UIKit.UIApplication app, Foundation.NSDictionary options) [0x00007]
in /Users/dev3/Virtual
Machines.localized/shared/stackoverflow_samples/EFCoreMigrationIssue/EFCoreMigrationIssue.iOS/AppDelegate.cs:26
at at (wrapper managed-to-native)
UIKit.UIApplication.UIApplicationMain(int,string[],intptr,intptr) at
UIKit.UIApplication.Main (System.String[] args, System.IntPtr
principal, System.IntPtr delegate) [0x00005] in
/Library/Frameworks/Xamarin.iOS.framework/Versions/13.6.0.12/src/Xamarin.iOS/UIKit/UIApplication.cs:86
at UIKit.UIApplication.Main (System.String[] args, System.String
principalClassName, System.String delegateClassName) [0x0000e] in
/Library/Frameworks/Xamarin.iOS.framework/Versions/13.6.0.12/src/Xamarin.iOS/UIKit/UIApplication.cs:65
at EFCoreMigrationIssue.iOS.Application.Main (System.String[] args)
[0x00001] in /Users/dev3/Virtual
Machines.localized/shared/stackoverflow_samples/EFCoreMigrationIssue/EFCoreMigrationIssue.iOS/Main.cs:17
Stacktrace on Android :
System.TypeLoadException: Could not resolve type with token 01000143
from typeref (expected class
'System.Diagnostics.CodeAnalysis.MaybeNullAttribute' in assembly
'netstandard, Version=2.1.0.0, Culture=neutral,
PublicKeyToken=cc7b13ffcd2ddd51') at
Microsoft.EntityFrameworkCore.Metadata.Conventions.NonNullableReferencePropertyConvention.Process
(Microsoft.EntityFrameworkCore.Metadata.Builders.IConventionPropertyBuilder
propertyBuilder) [0x00016] in <42de1eb635af4acabe9ad4af5d123ec7>:0
at
Microsoft.EntityFrameworkCore.Metadata.Conventions.NonNullableReferencePropertyConvention.ProcessPropertyAdded
(Microsoft.EntityFrameworkCore.Metadata.Builders.IConventionPropertyBuilder
propertyBuilder,
Microsoft.EntityFrameworkCore.Metadata.Conventions.IConventionContext1[TMetadata]
context) [0x00000] in <42de1eb635af4acabe9ad4af5d123ec7>:0 at
Microsoft.EntityFrameworkCore.Metadata.Conventions.Internal.ConventionDispatcher+ImmediateConventionScope.OnPropertyAdded
(Microsoft.EntityFrameworkCore.Metadata.Builders.IConventionPropertyBuilder
propertyBuilder) [0x00057] in <42de1eb635af4acabe9ad4af5d123ec7>:0
at
Microsoft.EntityFrameworkCore.Metadata.Conventions.Internal.ConventionDispatcher+RunVisitor.VisitOnPropertyAdded
(Microsoft.EntityFrameworkCore.Metadata.Conventions.Internal.ConventionDispatcher+OnPropertyAddedNode
node) [0x00011] in <42de1eb635af4acabe9ad4af5d123ec7>:0 at
Microsoft.EntityFrameworkCore.Metadata.Conventions.Internal.ConventionDispatcher+OnPropertyAddedNode.Accept
(Microsoft.EntityFrameworkCore.Metadata.Conventions.Internal.ConventionDispatcher+ConventionVisitor
visitor) [0x00000] in <42de1eb635af4acabe9ad4af5d123ec7>:0 at
Microsoft.EntityFrameworkCore.Metadata.Conventions.Internal.ConventionDispatcher+ConventionVisitor.Visit
(Microsoft.EntityFrameworkCore.Metadata.Conventions.Internal.ConventionDispatcher+ConventionNode
node) [0x00005] in <42de1eb635af4acabe9ad4af5d123ec7>:0 at
Microsoft.EntityFrameworkCore.Metadata.Conventions.Internal.ConventionDispatcher+ConventionVisitor.VisitConventionScope
(Microsoft.EntityFrameworkCore.Metadata.Conventions.Internal.ConventionDispatcher+ConventionScope
node) [0x00021] in <42de1eb635af4acabe9ad4af5d123ec7>:0 at
Microsoft.EntityFrameworkCore.Metadata.Conventions.Internal.ConventionDispatcher+ConventionBatch.Run
() [0x000e6] in <42de1eb635af4acabe9ad4af5d123ec7>:0 at
Microsoft.EntityFrameworkCore.Metadata.Conventions.Internal.ConventionDispatcher+ConventionBatch.Dispose
() [0x0001d] in <42de1eb635af4acabe9ad4af5d123ec7>:0 at
Microsoft.EntityFrameworkCore.Metadata.Conventions.Internal.ConventionDispatcher+ImmediateConventionScope.OnModelInitialized
(Microsoft.EntityFrameworkCore.Metadata.Builders.IConventionModelBuilder
modelBuilder) [0x0006f] in <42de1eb635af4acabe9ad4af5d123ec7>:0 at
Microsoft.EntityFrameworkCore.Metadata.Conventions.Internal.ConventionDispatcher.OnModelInitialized
(Microsoft.EntityFrameworkCore.Metadata.Builders.IConventionModelBuilder
modelBuilder) [0x00000] in <42de1eb635af4acabe9ad4af5d123ec7>:0 at
Microsoft.EntityFrameworkCore.Metadata.Internal.Model..ctor
(Microsoft.EntityFrameworkCore.Metadata.Conventions.ConventionSet
conventions) [0x0006d] in <42de1eb635af4acabe9ad4af5d123ec7>:0 at
Microsoft.EntityFrameworkCore.ModelBuilder..ctor
(Microsoft.EntityFrameworkCore.Metadata.Conventions.ConventionSet
conventions) [0x00012] in <42de1eb635af4acabe9ad4af5d123ec7>:0 at
Microsoft.EntityFrameworkCore.Infrastructure.ModelSource.CreateModel
(Microsoft.EntityFrameworkCore.DbContext context,
Microsoft.EntityFrameworkCore.Metadata.Conventions.Infrastructure.IConventionSetBuilder
conventionSetBuilder) [0x00012] in
<42de1eb635af4acabe9ad4af5d123ec7>:0 at
Microsoft.EntityFrameworkCore.Infrastructure.ModelSource+<>c__DisplayClass5_0.<GetModel>b__1
() [0x00000] in <42de1eb635af4acabe9ad4af5d123ec7>:0 at
System.Lazy1[T].ViaFactory (System.Threading.LazyThreadSafetyMode
mode) [0x00043] in <46c2fa109b574c7ea6739f9fe2350976>:0 at
System.Lazy1[T].ExecutionAndPublication (System.LazyHelper
executionAndPublication, System.Boolean useDefaultConstructor)
[0x00022] in <46c2fa109b574c7ea6739f9fe2350976>:0 at
System.Lazy1[T].CreateValue () [0x00074] in
<46c2fa109b574c7ea6739f9fe2350976>:0 at System.Lazy1[T].get_Value
() [0x0000a] in <46c2fa109b574c7ea6739f9fe2350976>:0 at
Microsoft.EntityFrameworkCore.Infrastructure.ModelSource.GetModel
(Microsoft.EntityFrameworkCore.DbContext context,
Microsoft.EntityFrameworkCore.Metadata.Conventions.Infrastructure.IConventionSetBuilder
conventionSetBuilder) [0x00048] in
<42de1eb635af4acabe9ad4af5d123ec7>:0 at
Microsoft.EntityFrameworkCore.Internal.DbContextServices.CreateModel
() [0x0003c] in <42de1eb635af4acabe9ad4af5d123ec7>:0 at
Microsoft.EntityFrameworkCore.Internal.DbContextServices.get_Model ()
[0x00020] in <42de1eb635af4acabe9ad4af5d123ec7>:0 at
Microsoft.EntityFrameworkCore.Infrastructure.EntityFrameworkServicesBuilder+<>c.<TryAddCoreServices>b__7_3
(System.IServiceProvider p) [0x00006] in
<42de1eb635af4acabe9ad4af5d123ec7>:0 at
Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitFactory
(Microsoft.Extensions.DependencyInjection.ServiceLookup.FactoryCallSite
factoryCallSite,
Microsoft.Extensions.DependencyInjection.ServiceLookup.RuntimeResolverContext
context) [0x0000d] in <afb136dae6154b1f956a9d6c25d25974>:0 at
Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor2[TArgument,TResult].VisitCallSiteMain
(Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceCallSite
callSite, TArgument argument) [0x00033] in
:0 at
Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitCache
(Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceCallSite
callSite,
Microsoft.Extensions.DependencyInjection.ServiceLookup.RuntimeResolverContext
context,
Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceProviderEngineScope
serviceProviderEngine,
Microsoft.Extensions.DependencyInjection.ServiceLookup.RuntimeResolverLock
lockType) [0x00059] in :0 at
Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitScopeCache
(Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceCallSite
singletonCallSite,
Microsoft.Extensions.DependencyInjection.ServiceLookup.RuntimeResolverContext
context) [0x00029] in :0 at
Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor2[TArgument,TResult].VisitCallSite
(Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceCallSite
callSite, TArgument argument) [0x00057] in
<afb136dae6154b1f956a9d6c25d25974>:0 at
Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitConstructor
(Microsoft.Extensions.DependencyInjection.ServiceLookup.ConstructorCallSite
constructorCallSite,
Microsoft.Extensions.DependencyInjection.ServiceLookup.RuntimeResolverContext
context) [0x0002c] in <afb136dae6154b1f956a9d6c25d25974>:0 at
Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor2[TArgument,TResult].VisitCallSiteMain
(Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceCallSite
callSite, TArgument argument) [0x0004f] in
:0 at
Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitCache
(Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceCallSite
callSite,
Microsoft.Extensions.DependencyInjection.ServiceLookup.RuntimeResolverContext
context,
Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceProviderEngineScope
serviceProviderEngine,
Microsoft.Extensions.DependencyInjection.ServiceLookup.RuntimeResolverLock
lockType) [0x00059] in :0 at
Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitScopeCache
(Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceCallSite
singletonCallSite,
Microsoft.Extensions.DependencyInjection.ServiceLookup.RuntimeResolverContext
context) [0x00029] in :0 at
Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor2[TArgument,TResult].VisitCallSite
(Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceCallSite
callSite, TArgument argument) [0x00057] in
<afb136dae6154b1f956a9d6c25d25974>:0 at
Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.Resolve
(Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceCallSite
callSite,
Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceProviderEngineScope
scope) [0x00012] in <afb136dae6154b1f956a9d6c25d25974>:0 at
Microsoft.Extensions.DependencyInjection.ServiceLookup.DynamicServiceProviderEngine+<>c__DisplayClass1_0.<RealizeService>b__0
(Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceProviderEngineScope
scope) [0x0003e] in <afb136dae6154b1f956a9d6c25d25974>:0 at
Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceProviderEngine.GetService
(System.Type serviceType,
Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceProviderEngineScope
serviceProviderEngineScope) [0x0003d] in
<afb136dae6154b1f956a9d6c25d25974>:0 at
Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceProviderEngineScope.GetService
(System.Type serviceType) [0x00013] in
<afb136dae6154b1f956a9d6c25d25974>:0 at
Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService
(System.IServiceProvider provider, System.Type serviceType) [0x00034]
in <f42dc3743e9a40bbad437e55b425d408>:0 at
Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService[T]
(System.IServiceProvider provider) [0x0000e] in
<f42dc3743e9a40bbad437e55b425d408>:0 at
Microsoft.EntityFrameworkCore.DbContext.get_DbContextDependencies ()
[0x00017] in <42de1eb635af4acabe9ad4af5d123ec7>:0 at
Microsoft.EntityFrameworkCore.DbContext.get_InternalServiceProvider ()
[0x000b5] in <42de1eb635af4acabe9ad4af5d123ec7>:0 at
Microsoft.EntityFrameworkCore.DbContext.Microsoft.EntityFrameworkCore.Infrastructure.IInfrastructure<System.IServiceProvider>.get_Instance
() [0x00000] in <42de1eb635af4acabe9ad4af5d123ec7>:0 at
Microsoft.EntityFrameworkCore.Infrastructure.DatabaseFacade.Microsoft.EntityFrameworkCore.Infrastructure.IInfrastructure<System.IServiceProvider>.get_Instance
() [0x00000] in <42de1eb635af4acabe9ad4af5d123ec7>:0 at
Microsoft.EntityFrameworkCore.RelationalDatabaseFacadeExtensions.GetRelationalService[TService]
(Microsoft.EntityFrameworkCore.Infrastructure.IInfrastructure1[T]
databaseFacade) [0x0000c] in :0 at
Microsoft.EntityFrameworkCore.RelationalDatabaseFacadeExtensions.Migrate
(Microsoft.EntityFrameworkCore.Infrastructure.DatabaseFacade
databaseFacade) [0x0000b] in :0 at
EFCoreMigrationIssue.Persistence.EFCoreMigrationIssueDbContext..ctor
(System.String databasePath) [0x0000f] in /Users/dev3/Virtual
Machines.localized/shared/stackoverflow_samples/EFCoreMigrationIssue/EFCoreMigrationIssue.Persistence/EFCoreMigrationIssueDbContext.cs:13
at EFCoreMigrationIssue.Persistence.FooRepository.GetDbContext ()
[0x00001] in /Users/dev3/Virtual
Machines.localized/shared/stackoverflow_samples/EFCoreMigrationIssue/EFCoreMigrationIssue.Persistence/FooRepository.cs:32
at EFCoreMigrationIssue.Persistence.FooRepository.GetAll () [0x00001]
in /Users/dev3/Virtual
Machines.localized/shared/stackoverflow_samples/EFCoreMigrationIssue/EFCoreMigrationIssue.Persistence/FooRepository.cs:25
at EFCoreMigrationIssue.MainPage.LoadFooList () [0x00001] in
/Users/dev3/Virtual
Machines.localized/shared/stackoverflow_samples/EFCoreMigrationIssue/EFCoreMigrationIssue/MainPage.xaml.cs:36 at EFCoreMigrationIssue.MainPage..ctor () [0x0003e] in
/Users/dev3/Virtual
Machines.localized/shared/stackoverflow_samples/EFCoreMigrationIssue/EFCoreMigrationIssue/MainPage.xaml.cs:27 at EFCoreMigrationIssue.App..ctor () [0x0000f] in /Users/dev3/Virtual
Machines.localized/shared/stackoverflow_samples/EFCoreMigrationIssue/EFCoreMigrationIssue/App.xaml.cs:13
at EFCoreMigrationIssue.Droid.MainActivity.OnCreate (Android.OS.Bundle
savedInstanceState) [0x0002f] in /Users/dev3/Virtual
Machines.localized/shared/stackoverflow_samples/EFCoreMigrationIssue/EFCoreMigrationIssue.Android/MainActivity.cs:24
at Android.App.Activity.n_OnCreate_Landroid_os_Bundle_ (System.IntPtr
jnienv, System.IntPtr native__this, System.IntPtr
native_savedInstanceState) [0x00011] in
<8c07a09624c14764b43f6b946a5a1f23>:0 at at (wrapper dynamic-method)
Android.Runtime.DynamicMethodNameCounter.8(intptr,intptr,intptr)
You need to call the
SQLitePCL.Batteries_V2.Init();
in the very beginning of your app. I think it is only required for iOS, but I have put it in my App.xaml.cs constructor, no matter the platform:
public App()
{
InitializeComponent();
// NOTE: The following line is required to load the platform specific assembly for SQLite.
// See: https://github.com/ericsink/SQLitePCL.raw/wiki/SQLitePCL.Batteries.Init
// And: https://github.com/aspnet/EntityFramework.Docs/issues/597
SQLitePCL.Batteries_V2.Init();
}
See:
SQLitePCL.Batteries.Init
and this GitHub issue:
Workarounds for Xamarin.iOS app with EFCore 2.0
As you have migrated to another database, I wish this would help others looking for the answer same as me!