realm in Xamarin, System.EntryPointNotfoundException when trying to use realm - realm

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.

Related

Cannot access a disposed object.\nObject name: 'PrimaryToolbarItem'

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.

Crashed when back to MainPage because of using SKGLView

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

Xamarin.Mac https://localhost httplclient

I have a local webapi which i use a selfsigned certificate to run on a pc.I am able to reach the webapi (written in .net core) using the browser (https://localhost:port/controller/method), but when i use httpclient on Mac OS Mojave i get an exception (High Sierra and Catalina works).
System.DllNotFoundException: libc.dylib assembly:<unknown assembly> type:<unknown type> member:(null)
at (wrapper managed-to-native) System.Net.NetworkInformation.CommonUnixIPGlobalProperties.getdomainname(byte[],int)
at System.Net.NetworkInformation.CommonUnixIPGlobalProperties.get_DomainName () [0x0000b] in <4b9a7f543fd447a3be5e54f34ee219b2>:0
at System.Net.CookieContainer..ctor () [0x0003f] in <4b9a7f543fd447a3be5e54f34ee219b2>:0
at System.Net.Http.MonoWebRequestHandler.get_CookieContainer () [0x0000a] in <e45d721af82a41d98156aeda80e9ce53>:0
at System.Net.Http.MonoWebRequestHandler.CreateWebRequest (System.Net.Http.HttpRequestMessage request) [0x000f5] in <e45d721af82a41d98156aeda80e9ce53>:0
at System.Net.Http.MonoWebRequestHandler.SendAsync (System.Net.Http.HttpRequestMessage request, System.Threading.CancellationToken cancellationToken) [0x0003e] in <e45d721af82a41d98156aeda80e9ce53>:0
at System.Net.Http.HttpClient.SendAsyncWorker (System.Net.Http.HttpRequestMessage request, System.Net.Http.HttpCompletionOption completionOption, System.Threading.CancellationToken cancellationToken) [0x000e8] in <e45d721af82a41d98156aeda80e9ce53>:0
at Mac_Installer.ViewController.Timer_Elapsed (System.Object sender, System.Timers.ElapsedEventArgs e) [0x000bd] in <3581d802103c47bbbf47f26a2763b24c>:0
I have read up and it seems like i need to set the DYLD_FALLBACK_LIBRARY_PATH to /usr/lib (I can see the file - libc.dylib - is there), believe i should add it in the info.plist as an environment variable, but it still fails, or i am doing it wrong.
Any help appreciciated.
If you enabled hardened runtime, try adding "Allow DYLD Environment Variables Entitlement" (com.apple.security.cs.allow-dyld-environment-variables) into your Entitlements.plist.
I just copy libc.dylib. over to the app MonoBundle or Resources folder. The Dll can be found here: https://github.com/facilityweb/Dlls/blob/master/libc.dylib
Another Solution is import the lib MainClass, like follows:
static class MainClass
{
static void Main(string[] args)
{
//solved mojave notfound dll exception
IntPtr p = Dlfcn.dlopen("/usr/lib/libc.dylib", 0);
NSApplication.Init();
NSApplication.SharedApplication.Delegate = new AppDelegate();
NSApplication.Main(args);
}
}

Xamarin Forms - Sqlite android Oreo runtime.JavaProxyThrowable

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.

Using Azure storage on Mac with ASP.NET vNext

Trying to read data from Azure TableStorage in MVC 6 application on Mac.
It works on PC, but when on Mac it used to give this error:
TypeLoadException: Could not load type 'Microsoft.WindowsAzure.Storage.Core.Executor.RESTCommand`1[Microsoft.WindowsAzure.Storage.Table.TableResult]' from assembly 'Microsoft.WindowsAzure.Storage, Version=4.3.2.0, Culture=neutral, PublicKeyToken=null'.
Microsoft.WindowsAzure.Storage.Table.TableOperation.ExecuteAsync (Microsoft.WindowsAzure.Storage.Table.CloudTableClient client, System.String tableName, Microsoft.WindowsAzure.Storage.Table.TableRequestOptions requestOptions, Microsoft.WindowsAzure.Storage.OperationContext operationContext, CancellationToken cancellationToken) [0x00000] in <filename unknown>, line 0Stack Query Cookies Headers Environment
TypeLoadException: Could not load type 'Microsoft.WindowsAzure.Storage.Core.Executor.RESTCommand`1[Microsoft.WindowsAzure.Storage.Table.TableResult]' from assembly 'Microsoft.WindowsAzure.Storage, Version=4.3.2.0, Culture=neutral, PublicKeyToken=null'.
Microsoft.WindowsAzure.Storage.Table.TableOperation.ExecuteAsync (Microsoft.WindowsAzure.Storage.Table.CloudTableClient client, System.String tableName, Microsoft.WindowsAzure.Storage.Table.TableRequestOptions requestOptions, Microsoft.WindowsAzure.Storage.OperationContext operationContext, CancellationToken cancellationToken) [0x00000] in <filename unknown>
Microsoft.WindowsAzure.Storage.Table.CloudTableClient.ExecuteAsync (System.String tableName, Microsoft.WindowsAzure.Storage.Table.TableOperation operation, Microsoft.WindowsAzure.Storage.Table.TableRequestOptions requestOptions, Microsoft.WindowsAzure.Storage.OperationContext operationContext, CancellationToken cancellationToken) [0x00000] in <filename unknown>
Microsoft.WindowsAzure.Storage.Table.CloudTable+<>c__DisplayClass4+<<ExistsAsync>b__5>d__0.MoveNext () [0x00000] in <filename unknown>
--- End of stack trace from previous location where exception was thrown ---
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x00000] in <filename unknown>
System.Runtime.CompilerServices.TaskAwaiter`1[System.Boolean].GetResult () [0x00000] in <filename unknown>
After following this discussion and installing System.Net.Http package using kpm I started to get a new error:
An unhandled exception occurred while processing the request.NullReferenceException: Object reference not set to an instance of an object
Microsoft.WindowsAzure.Storage.Shared.Protocol.HttpClientFactory.BuildHttpClient[TableResult] (Microsoft.WindowsAzure.Storage.Core.Executor.RESTCommand`1 cmd, System.Net.Http.HttpMessageHandler handler, Boolean useVersionHeader, Microsoft.WindowsAzure.Storage.OperationContext operationContext) [0x00000] in <filename unknown>, line 0
Note:
I had the System.Net.Http package installed in "aspnetcore50": { "dependencies": { ... } }, but it seems like it had to be installed in the common dependencies
Any idea why that might happen and how to fix it?
You cannot use Azure Storage .NET client under aspnetcore50, it's not available for this runtime. You need to pull it under aspnet50 (dnx451 now).

Resources