SIGABRT: Cannot access a disposed object. Object name: 'SKGLView'.
We are using SKGLView in MainPage, sometimes back from another view, this error will show and app crash. I have no idea, and here is the log from App Center.
NSObject.get_SuperHandle ()
/Users/builder/azdo/_work/1/s/xamarin-macios/src/Foundation/NSObject2.cs:471
GLKView.Display ()
/Users/builder/azdo/_work/1/s/xamarin-macios/src/build/ios/native/GLKit/GLKView.g.cs:152
SKGLViewRenderer+<>c__DisplayClass4_0.b__1 ()
NSAsyncActionDispatcher.Apply ()
/Users/builder/azdo/_work/1/s/xamarin-macios/src/Foundation/NSAction.cs:152
(wrapper managed-to-native)
UIKit.UIApplication.UIApplicationMain(int,string[],intptr,intptr)
UIApplication.Main (System.String[] args, System.IntPtr principal,
System.IntPtr delegate)
/Users/builder/azdo/_work/1/s/xamarin-macios/src/UIKit/UIApplication.cs:86
Application.Main (System.String[] args)
Finally, we solve it just by setting HasRenderLoop property for SKGLView using code, not in Xaml.
Reference link: https://github.com/mono/SkiaSharp/issues/870
Related
This is a sample application attempting the Xamarin Forms navigation capability.
We have an event handler with this simple logic:
async void Button_Clicked(System.Object sender, System.EventArgs e)
{
await Shell.Current.GoToAsync(nameof(SchoolList));
}
We also have the route registered in App.xaml.cs as follows:
public partial class App : Application
{
public App()
{
InitializeComponent();
MainPage = new MainPage();
Routing.RegisterRoute(nameof(SchoolList), typeof(SchoolList));
}
However, when the corresponding button is clicked, we get the error below:
System.NullReferenceException: Object reference not set to an instance of an object.
at cross_app1.MainPage.Button_Clicked (System.Object sender, System.EventArgs e) [0x0000f] in /Users/klaus.nji/Projects/cross-app1/cross-app1/MainPage.xaml.cs:18
at System.Runtime.CompilerServices.AsyncMethodBuilderCore+<>c.<ThrowAsync>b__7_0 (System.Object state) [0x00000] in /Users/builder/jenkins/workspace/archive-mono/2020-02/android/release/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/AsyncMethodBuilder.cs:1021
at Android.App.SyncContext+<>c__DisplayClass2_0.<Post>b__0 () [0x00000] in /Users/builder/azdo/_work/1/s/xamarin-android/src/Mono.Android/Android.App/SyncContext.cs:36
at Java.Lang.Thread+RunnableImplementor.Run () [0x00008] in /Users/builder/azdo/_work/1/s/xamarin-android/src/Mono.Android/Java.Lang/Thread.cs:36
at Java.Lang.IRunnableInvoker.n_Run (System.IntPtr jnienv, System.IntPtr native__this) [0x00008] in /Users/builder/azdo/_work/1/s/xamarin-android/src/Mono.Android/obj/Release/monoandroid10/android-30/mcw/Java.Lang.IRunnable.cs:84
at at (wrapper dynamic-method) Android.Runtime.DynamicMethodNameCounter.39(intptr,intptr)
The system is Mac Catalina v10.15.7, IDE is Visual Studio 2019 for Mac and I have the Andriod SDK installed and able to see other aspects of the app.
It looks like you don’t have a Shell, so Shell.Current is null.
What Shell example did you follow?
MainPage = new MainPage(); means your app is pointing to a page of type MainPage. To use Shell (Route) navigation, it needs to be pointing to a Shell.
I would expect to see MainPage = new AppShell();.
There may be other details missing, so be sure to follow a working example, such as Xaminals.
The new AppShell line can be seen in https://github.com/xamarin/xamarin-forms-samples/blob/main/UserInterface/Xaminals/Xaminals/App.xaml.cs.
Note: Its possible to navigate in Xamarin Forms without having Shell, nor defining routes. (Personally, I dislike the Shell, so I don’t use it.) You can define MainPage as a NavigationPage (see its doc). Or you can simply set App.MainPage to different pages, to move between them, without a navigation stack.
I created a ToolbaItems in a ContentPage that is a ShellContent from FlyoutItem - I am using ShellApp.
<ContentPage.ToolbarItems>
<ToolbarItem
x:Name="xicon"
Clicked=""
IconImageSource="{local1:ImageResource MobileApp.Resources.Images.x.png}"
Text="Saw X" />
<ToolbarItem
x:Name="yicon"
Clicked=""
IconImageSource="{local1:ImageResource MobileApp.Resources.Images.y.png}"
Text="Saw Y" />
<ToolbarItem
x:Name="zicon"
Clicked=""
IconImageSource="{local1:ImageResource MobileApp.Resources.Images.z.png}"
Text="Saw Z" />
</ContentPage.ToolbarItems>
In Android it works well, but in iOS I got an error:
Message "Cannot access a disposed object.\n
Object name: 'PrimaryToolbarItem'." string
$exception {System.ObjectDisposedException: Cannot access a disposed object.
Object name: 'PrimaryToolbarItem'.
at Foundation.NSObject.get_SuperHandle () [0x00012] in /Users/builder/azdo/_work/1/s/xamarin-macios/src/Foundation/NSObject2.cs:469
at UIKit.UIBarButtonItem.set_Image (UIKit.UIImage value) [0x0002b] in /Users/builder/azdo/_work/1/s/xamarin-macios/src/build/ios/native/UIKit/UIBarButtonItem.g.cs:827
at Xamarin.Forms.Platform.iOS.ToolbarItemExtensions+PrimaryToolbarItem.UpdateIconAndStyle () [0x00031] in D:\a\1\s\Xamarin.Forms.Platform.iOS\Extensions\ToolbarItemExtensions.cs:84
at System.Runtime.CompilerServices.AsyncMethodBuilderCore+<>c.<ThrowAsync>b__7_0 (System.Object state) [0x00000] in /Library/Frameworks/Xamarin.iOS.framework/Versions/Current/src/Xamarin.iOS/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/AsyncMethodBuilder.cs:1021
at Foundation.NSAsyncSynchronizationContextDispatcher.Apply () [0x00000] in /Users/builder/azdo/_work/1/s/xamarin-macios/src/Foundation/NSAction.cs:178
--- End of stack trace from previous location where exception was thrown ---
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 /Users/builder/azdo/_work/1/s/xamarin-macios/src/UIKit/UIApplication.cs:86
at UIKit.UIApplication.Main (System.String[] args, System.String principalClassName, System.String delegateClassName) [0x0000e] in /Users/builder/azdo/_work/1/s/xamarin-macios/src/UIKit/UIApplication.cs:65
at Toretto.MobileApp.iOS.Application.Main (System.String[] args) [0x00001] in C:\Projects\Toretto\Toretto.MobileApp\src\Toretto.MobileApp\Toretto.MobileApp.iOS\Main.cs:17 } System.ObjectDisposedException
If I remove theses items in the constructor of the ContentPage it does not crash, I tried to use only Text, in Android I am using icon and works...
public HomePage()
{
InitializeComponent();
if (DeviceInfo.Platform == DevicePlatform.iOS)
{
this.ToolbarItems.Clear();
}
}
Is this a bug? In github I saw few issue about toolbar.
Yes, it is just the case. It is a known issue, and xamarin development team have added this to To do in xamarin form v5.0.1.
You can follow it up here:https://github.com/xamarin/Xamarin.Forms/issues/6387.
We are sorry for the inconvenience.And thanks for your support for xamarin.
When I use the code below in my xamarin.forms project to check if User object exist in akavache cache, I am getting the exception below. the same code or any akavache query works somewhere else but crashes in onStart method only. I believe that I am initializing akavache in constructor already. I tried exact same code using mobile center to query locally (local sqlite) user data and I get the same exception. I think that this should be something to do with the sqlite as both akavache and mobile center uses similar sqlite libraries. Does anybody know why it doesnt work in OnStart method?
public App()
{
Microsoft.Azure.Mobile.MobileCenter.Start("android=key" +
"uwp=key",
typeof(Microsoft.Azure.Mobile.Analytics.Analytics), typeof(Microsoft.Azure.Mobile.Crashes.Crashes));
Akavache.BlobCache.ApplicationName = "myApp";
Akavache.BlobCache.EnsureInitialized();
ServiceLocator.Add<ICloudService, AzureCloudService>();
InitializeComponent();
}
protected async override void OnStart()
{
try
{
var User= await BlobCache.UserAccount.GetObject<User>("User");
if (User != null)
Helpers.Settings.IsLoggedIn = true;
else
Helpers.Settings.IsLoggedIn = false;
}
catch (Exception)
{
Helpers.Settings.IsLoggedIn = false;
}
ShowMainPageOrLoginPage();
}
11-13 02:08:14.761 E/MobileCenterCrashes( 6308): Unhandled Exception:
11-13 02:08:14.761 E/MobileCenterCrashes( 6308):
System.NullReferenceException: Object reference not set to an instance
of an object. 11-13 02:08:14.761 E/MobileCenterCrashes( 6308): at
Xamarin.Forms.Platform.Android.AppCompat.Platform.LayoutRootPage
(Xamarin.Forms.Page page, System.Int32 width, System.Int32 height)
[0x0000c] in
D:\agent_work\1\s\Xamarin.Forms.Platform.Android\AppCompat\Platform.cs:291
11-13 02:08:14.761 E/MobileCenterCrashes( 6308): at
Xamarin.Forms.Platform.Android.AppCompat.Platform.Xamarin.Forms.Platform.Android.IPlatformLayout.OnLayout
(System.Boolean changed, System.Int32 l, System.Int32 t, System.Int32
r, System.Int32 b) [0x00003] in
D:\agent_work\1\s\Xamarin.Forms.Platform.Android\AppCompat\Platform.cs:199
11-13 02:08:14.761 E/MobileCenterCrashes( 6308): at
Xamarin.Forms.Platform.Android.PlatformRenderer.OnLayout
(System.Boolean changed, System.Int32 l, System.Int32 t, System.Int32
r, System.Int32 b) [0x0000e] in
D:\agent_work\1\s\Xamarin.Forms.Platform.Android\PlatformRenderer.cs:73
11-13 02:08:14.761 E/MobileCenterCrashes( 6308): at
Android.Views.ViewGroup.n_OnLayout_ZIIII (System.IntPtr jnienv,
System.IntPtr native__this, System.Boolean changed, System.Int32 l,
System.Int32 t, System.Int32 r, System.Int32 b) [0x00008] in
:0
EDIT:
This issue is definetly caused by akavache. Message is really strange. it looks like that akavache has some relation with LayoutRootPage.
See my code above, I get User object from akavache cache and user object defines if I should show Login Page or Main Page. If I move ShowMainPageOrLoginPage();function above akavache call, it works just fine. So it seems that you cant make any query with akavache before the rootlayoutpage - Main page is set or loaded.
I had the same problem once before, for some reason if you initialize using the static method it doesn't work all the time.
Doesn't work
IBlobCache _cache = BlobCache.LocalMachine;
Does Work
IBlobCache _cache = new SQLitePersistentBlobCache(systemPath + "/CacheUtils.db");
If you want to find the systemPath you can use this in either your Android or iOS
systemPath = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal);
I am using Sqlite in a Xamarin Forms Portable project and I successfully run my application on iOS and UWP. On Android, I can run my application on a Android 6.0 emulator but in Android Oreo although app is installed, it crashes on startup. I am facing the following issue.
Issue:
android.runtime.JavaProxyThrowable: at (wrapper managed-to-native)
SQLite.Net.Platform.XamarinAndroid.SQLiteApiAndroidInternal:sqlite3_open_v2
(byte[],intptr&,int,intptr) at
SQLite.Net.Platform.XamarinAndroid.SQLiteApiAndroid.Open
(System.Byte[] filename, SQLite.Net.Interop.IDbHandle& db,
System.Int32 flags, System.IntPtr zvfs) [0x00000] in
<8dbf6ff85082469fb9d4dfaa9eae6b69>:0 at
SQLite.Net.SQLiteConnection..ctor (SQLite.Net.Interop.ISQLitePlatform
sqlitePlatform, System.String databasePath,
SQLite.Net.Interop.SQLiteOpenFlags openFlags, System.Boolean
storeDateTimeAsTicks, SQLite.Net.IBlobSerializer serializer,
System.Collections.Generic.IDictionary2[TKey,TValue] tableMappings,
System.Collections.Generic.IDictionary2[TKey,TValue]
extraTypeMappings, SQLite.Net.IContractResolver resolver) [0x000a2] in
<8f2bb39aeff94a30a8628064be9c7efe>:0 at
SQLite.Net.SQLiteConnectionWithLock..ctor
(SQLite.Net.Interop.ISQLitePlatform sqlitePlatform,
SQLite.Net.SQLiteConnectionString connectionString,
System.Collections.Generic.IDictionary2[TKey,TValue] tableMappings,
System.Collections.Generic.IDictionary2[TKey,TValue]
extraTypeMappings) [0x0002e] in <8f2bb39aeff94a30a8628064be9c7efe>:0
at project.Models.Database+<>c__DisplayClass1_0.<.ctor>b__0 ()
[0x0001d] in <7df232f34ab8474d9153e3809af4eda8>:0 at
SQLite.Net.Async.SQLiteAsyncConnection.GetConnection () [0x00000] in
<563d605f9f014eeeb32fd4a27b4d142e>:0 at
SQLite.Net.Async.SQLiteAsyncConnection+<>c__DisplayClass11_0.b__0
() [0x00006] in <563d605f9f014eeeb32fd4a27b4d142e>:0 at
System.Threading.Tasks.Task`1[TResult].InnerInvoke () [0x0000f] in
:0 at
System.Threading.Tasks.Task.Execute () [0x00010] in
:0 at
mono.java.lang.RunnableImplementor.n_run (Native Method) at
mono.java.lang.RunnableImplementor.run (RunnableImplementor.java:30)
at android.os.Handler.handleCallback (Handler.java:789) at
android.os.Handler.dispatchMessage (Handler.java:98) at
android.os.Looper.loop (Looper.java:164) at
android.app.ActivityThread.main (ActivityThread.java:6541) at
java.lang.reflect.Method.invoke (Native Method) at
com.android.internal.os.Zygote$MethodAndArgsCaller.run
(Zygote.java:240) at com.android.internal.os.ZygoteInit.main
(ZygoteInit.java:767)
In order to create the connection:
public Database(string databaseName)
{
var pathToDatabaseFile = DependencyService.Get<Interfaces.ISQLite>().GetLocalPathToFile(databaseName);
var platform = DependencyService.Get<Interfaces.IPlatformProvider>().GetPlatform();
_connection = new SQLiteAsyncConnection(() =>
new SQLiteConnectionWithLock(platform, new SQLiteConnectionString(pathToDatabaseFile, false)));
_connection.CreateTableAsync<SqlitePage>().Wait();
}
In every project GetPlatform and GetLocalPathToFile are implemented:
return new SQLitePlatformAndroid();
and
return Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Personal), fileName);
The packages I use for Sqlite are:
SQLite.Net.Async-PCL
SQLite.Net.Core-PCL
SQLite.Net-PCL
Any ideas?
You should change to sqlite-net-pcl, since Android 6+, some permission have changed.
https://www.nuget.org/packages/sqlite-net-pcl/
I switched to this PCL, and everything works like a charm.
I have installed realm in a Xamarin app and when I try to use an object (count, write, etc) it gives me a System.EntryPointNotFoundException.
Below code:
_realm = Realm.GetInstance();
_realm.Write(() =>
{
var myConfig = _realm.CreateObject<Config>();
myConfig.Email = "";
myConfig.User = "";
});
System.EntryPointNotFoundException: shared_realm_begin_transaction
at at (wrapper managed-to-native) Realms.NativeSharedRealm:begin_transaction (Realms.SharedRealmHandle)
at Realms.Transaction..ctor (Realms.SharedRealmHandle sharedRealmHandle) [0x0000d] in :0
at Realms.Realm.BeginWrite () [0x00000] in :0
at Realms.Realm.Write (System.Action action) [0x00000] in :0
at rasoApp.ConfigViewModel..ctor () [0x00025] in /Users/luis/Projects/rasoApp/rasoApp/viewModels/ConfigViewModel.cs:22
at rasoApp.ConfigPage.SetBinding (Xamarin.Forms.BindableProperty targetProperty, Xamarin.Forms.BindingBase binding) [0x0000e] in /Users/luis/Projects/rasoApp/rasoApp/views/ConfigPage.xaml.cs:13
at rasoApp.HomePage.btnOpenConfig (System.Object sender, System.EventArgs e) [0x00007] in /Users/luis/Projects/rasoApp/rasoApp/views/HomePage.xaml.cs:18
at Xamarin.Forms.Button.Xamarin.Forms.IButtonController.SendClicked () [0x00020] in :0
at Xamarin.Forms.Platform.iOS.ButtonRenderer.OnButtonTouchUpInside (System.Object sender, System.EventArgs eventArgs) [0x0000e] in :0
at UIKit.UIControlEventProxy.Activated () [0x00007] in /Users/builder/data/lanes/3412/3cf8aaed/source/maccore/src/UIKit/UIControl.cs:38
at at (wrapper managed-to-native) UIKit.UIApplication:UIApplicationMain (int,string[],intptr,intptr)
at UIKit.UIApplication.Main (System.String[] args, IntPtr principal, IntPtr delegate) [0x00005] in /Users/builder/data/lanes/3412/3cf8aaed/source/maccore/src/UIKit/UIApplication.cs:79
at UIKit.UIApplication.Main (System.String[] args, System.String principalClassName, System.String delegateClassName) [0x00038] in /Users/builder/data/lanes/3412/3cf8aaed/source/maccore/src/UIKit/UIApplication.cs:63
at rasoApp.iOS.Application.Main (System.String[] args) [0x00008] in /Users/luis/Projects/rasoApp/iOS/Main.cs:17
Congratulations on an interesting problem!
I have seen a similar error but only in recent work I was doing refining code generation, when I generated bad IL code. We have no previous issues recorded nor any discussions of EntryPointNotFoundException messages that I can find.
If you try building one of our examples from the Realm source download, such as QuickJournal does that work?
If you can send a full project demonstrating the problem to help#realm.io that is probably the fastest way to work out what is happening.
Update 2016-07-11
Looking at another SO question made me think of a few more things to try:
Does this happen on all platforms?
- Do you have Full Linking enabled in Xamarin studio?
Earlier Suggestions
Does your app have a PCL containing that logic?
Did you also install the Realm NuGet into the main application (IOS or Android) projects? That is a necessary step. The main Realm libraries are only included with the platform-specific dlls which NuGet adds to IOS or Android projects.