Realm Xamarin - Error on GetInstance() - c#

I set my main page in this way:
namespace MyNamepage
{
public partial class MyPage: ContentPage
{
private Realm realm;
public MyPage()
{
InitializeComponent();
this.realm = Realm.GetInstance();
}
}
}
Debugging the Android project i got this error and the app crash:
System.Reflection.TargetInvocationException: Exception has been thrown
by the target of an invocation.
I've installed "Realm" in PCL and in Droid Project using NuGet but it seems doesn't work.
If i remove the GetInstance() call, the app doesn't crash;
Stack trace:
10-17 10:36:31.935 I/MonoDroid(31518): UNHANDLED EXCEPTION:
10-17 10:36:31.955 I/MonoDroid(31518): System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.PlatformNotSupportedException: The PCL build of Realm is being linked which probably means you need to use NuGet or otherwise link a platform-specific Realm.dll to your main application.
10-17 10:36:31.955 I/MonoDroid(31518): at Realms.RealmPCLHelpers.ThrowProxyShouldNeverBeUsed () [0x00000] in <filename unknown>:0
10-17 10:36:31.955 I/MonoDroid(31518): at Realms.Realm.GetInstance (Realms.RealmConfiguration config) [0x00000] in <filename unknown>:0
10-17 10:36:31.955 I/MonoDroid(31518): at MyPack.SidePage.MyPage..ctor () [0x00008] in C:\Users\User\documents\visual studio 2015\Projects\MyPack\MyPack\MyPack\SidePage\MyPage.xaml.cs:14
10-17 10:36:31.955 I/MonoDroid(31518): at (wrapper managed-to-native) System.Reflection.MonoCMethod:InternalInvoke (System.Reflection.MonoCMethod,object,object[],System.Exception&)
10-17 10:36:31.955 I/MonoDroid(31518): at System.Reflection.MonoCMethod.InternalInvoke (System.Object obj, System.Object[] parameters) [0x00002] in /Users/builder/data/lanes/3415/7db2aac3/source/mono/mcs/class/corlib/System.Reflection/MonoMethod.cs:644
10-17 10:36:31.965 I/MonoDroid(31518): --- End of inner exception stack trace ---
10-17 10:36:31.965 I/MonoDroid(31518): at System.Reflection.MonoCMethod.InternalInvoke (System.Object obj, System.Object[] parameters) [0x00016] in /Users/builder/data/lanes/3415/7db2aac3/source/mono/mcs/class/corlib/System.Reflection/MonoMethod.cs:650
10-17 10:36:31.965 I/MonoDroid(31518): at System.RuntimeType.CreateInstanceMono (Boolean nonPublic) [0x000ca] in /Users/builder/data/lanes/3415/7db2aac3/source/mono/mcs/class/corlib/ReferenceSources/RuntimeType.cs:115
10-17 10:36:31.965 I/MonoDroid(31518): at System.RuntimeType.CreateInstanceSlow (Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, System.Threading.StackCrawlMark& stackMark) [0x0001a] in /Users/builder/data/lanes/3415/7db2aac3/source/mono/mcs/class/corlib/ReferenceSources/RuntimeType.cs:89
10-17 10:36:31.965 I/MonoDroid(31518): at System.RuntimeType.CreateInstanceDefaultCtor (Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, System.Threading.StackCrawlMark& stackMark) [0x0002a] in /Users/builder/data/lanes/3415/7db2aac3/source/mono/external/referencesource/mscorlib/system/rttype.cs:5599
10-17 10:36:31.965 I/MonoDroid(31518): at System.Activator.CreateInstance (System.Type type, Boolean nonPublic) [0x00040] in /Users/builder/data/lanes/3415/7db2aac3/source/mono/external/referencesource/mscorlib/system/activator.cs:201
10-17 10:36:31.965 I/MonoDroid(31518): at System.Activator.CreateInstance (System.Type type) [0x00000] in /Users/builder/data/lanes/3415/7db2aac3/source/mono/external/referencesource/mscorlib/system/activator.cs:134
10-17 10:36:31.965 I/MonoDroid(31518): at MyPack.MainPage.OnItemSelected (System.Object sender, Xamarin.Forms.SelectedItemChangedEventArgs e) [0x00016] in C:\Users\User\documents\visual studio 2015\Projects\MyPack\MyPack\MyPack\MainPage.xaml.cs:24
10-17 10:36:31.965 I/MonoDroid(31518): at (wrapper delegate-invoke) System.EventHandler`1[Xamarin.Forms.SelectedItemChangedEventArgs]:invoke_void_object_TEventArgs (object,Xamarin.Forms.SelectedItemChangedEventArgs)
10-17 10:36:31.975 I/MonoDroid(31518): at Xamarin.Forms.ListView.OnSelectedItemChanged (Xamarin.Forms.BindableObject bindable, System.Object oldValue, System.Object newValue) [0x0001c] in <filename unknown>:0
10-17 10:36:31.975 I/MonoDroid(31518): at Xamarin.Forms.BindableObject.SetValueActual (Xamarin.Forms.BindableProperty property, Xamarin.Forms.BindablePropertyContext context, System.Object value, Boolean currentlyApplying, SetValueFlags attributes, Boolean silent) [0x0010e] in <filename unknown>:0
10-17 10:36:31.975 I/MonoDroid(31518): at Xamarin.Forms.BindableObject.SetValueCore (Xamarin.Forms.BindableProperty property, System.Object value, SetValueFlags attributes, SetValuePrivateFlags privateAttributes) [0x0014b] in <filename unknown>:0
10-17 10:36:31.975 I/MonoDroid(31518): at Xamarin.Forms.BindableObject.SetValueCore (Xamarin.Forms.BindableProperty property, System.Object value, SetValueFlags attributes) [0x00000] in <filename unknown>:0
10-17 10:36:31.975 I/MonoDroid(31518): at Xamarin.Forms.ListView.NotifyRowTapped (Int32 groupIndex, Int32 inGroupIndex, Xamarin.Forms.Cell cell) [0x0004c] in <filename unknown>:0
10-17 10:36:31.975 I/MonoDroid(31518): at Xamarin.Forms.ListView.NotifyRowTapped (Int32 index, Xamarin.Forms.Cell cell) [0x00023] in <filename unknown>:0
10-17 10:36:31.975 I/MonoDroid(31518): at Xamarin.Forms.Platform.Android.ListViewAdapter.HandleItemClick (Android.Widget.AdapterView parent, Android.Views.View view, Int32 position, Int64 id) [0x00056] in <filename unknown>:0
10-17 10:36:31.975 I/MonoDroid(31518): at Xamarin.Forms.Platform.Android.CellAdapter.OnItemClick (Android.Widget.AdapterView parent, Android.Views.View view, Int32 position, Int64 id) [0x0002e] in <filename unknown>:0
10-17 10:36:31.975 I/MonoDroid(31518): at Android.Widget.AdapterView+IOnItemClickListenerInvoker.n_OnItemClick_Landroid_widget_AdapterView_Landroid_view_View_IJ (IntPtr jnienv, IntPtr native__this, IntPtr native_parent, IntPtr native_view, Int32 position, Int64 id) [0x00019] in /Users/builder/data/lanes/3415/7db2aac3/source/monodroid/src/Mono.Android/platforms/android-23/src/generated/Android.Widget.AdapterView.cs:215
10-17 10:36:31.975 I/MonoDroid(31518): at (wrapper dynamic-method) System.Object:585983a8-79f2-48a3-ac33-5b4c905219f1 (intptr,intptr,intptr,intptr,int,long)
10-17 10:36:31.995 D/Mono (31518): DllImport searching in: '__Internal' ('(null)').
10-17 10:36:31.995 D/Mono (31518): Searching for 'java_interop_jnienv_throw'.
10-17 10:36:31.995 D/Mono (31518): Probing 'java_interop_jnienv_throw'.
10-17 10:36:31.995 D/Mono (31518): Found as 'java_interop_jnienv_throw'.
An unhandled exception occured.
10-17 10:36:34.115 E/mono (31518):
10-17 10:36:34.115 E/mono (31518): Unhandled Exception:
10-17 10:36:34.115 E/mono (31518): System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.PlatformNotSupportedException: The PCL build of Realm is being linked which probably means you need to use NuGet or otherwise link a platform-specific Realm.dll to your main application.
10-17 10:36:34.115 E/mono (31518): at Realms.RealmPCLHelpers.ThrowProxyShouldNeverBeUsed () [0x00000] in <filename unknown>:0
10-17 10:36:34.115 E/mono (31518): at Realms.Realm.GetInstance (Realms.RealmConfiguration config) [0x00000] in <filename unknown>:0
10-17 10:36:34.115 E/mono (31518): at MyPack.SidePage.MyPage..ctor () [0x00008] in C:\Users\User\documents\visual studio 2015\Projects\MyPack\MyPack\MyPack\SidePage\MyPage.xaml.cs:14
10-17 10:36:34.115 E/mono (31518): at (wrapper managed-to-native) System.Reflection.MonoCMethod:InternalInvoke (System.Reflection.MonoCMethod,object,object[],System.Exception&)
10-17 10:36:34.115 E/mono (31518): at System.Reflection.MonoCMethod.InternalInvoke (System.Object obj, System.Object[] parameters) [0x00002] in /Users/builder/data/lanes/3415/7db2aac3/source/mono/mcs/class/corlib/System.Reflection/MonoMethod.cs:644
10-17 10:36:34.115 E/mono (31518): --- End of inner exception stack trace ---
10-17 10:36:34.115 E/mono (31518): at (wrapper dynamic-method) System.Object:585983a8-79f2-48a3-ac33-5b4c905219f1 (intptr,intptr,intptr,intptr,int,long)
10-17 10:36:34.115 E/mono (31518): at (wrapper native-to-managed) System.Object:585983a8-79f2-48a3-ac33-5b4c905219f1 (intptr,intptr,intptr,intptr,int,long)
10-17 10:36:34.115 E/mono-rt (31518): [ERROR] FATAL UNHANDLED EXCEPTION: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.PlatformNotSupportedException: The PCL build of Realm is being linked which probably means you need to use NuGet or otherwise link a platform-specific Realm.dll to your main application.
10-17 10:36:34.115 E/mono-rt (31518): at Realms.RealmPCLHelpers.ThrowProxyShouldNeverBeUsed () [0x00000] in <filename unknown>:0
10-17 10:36:34.115 E/mono-rt (31518): at Realms.Realm.GetInstance (Realms.RealmConfiguration config) [0x00000] in <filename unknown>:0
10-17 10:36:34.115 E/mono-rt (31518): at MyPack.SidePage.MyPage..ctor () [0x00008] in C:\Users\User\documents\visual studio 2015\Projects\MyPack\MyPack\MyPack\SidePage\MyPage.xaml.cs:14
10-17 10:36:34.115 E/mono-rt (31518): at (wrapper managed-to-native) System.Reflection.MonoCMethod:InternalInvoke (System.Reflection.MonoCMethod,object,object[],System.Exception&)
10-17 10:36:34.115 E/mono-rt (31518): at System.Reflection.MonoCMethod.InternalInvoke (System.Object obj, System.Object[] parameters) [0x00002] in /Users/builder/data/lanes/3415/7db2aac3/source/mono/mcs/class/corlib/System.Reflection/MonoMethod.cs:644
10-17 10:36:34.115 E/mono-rt (31518): --- End of inner exception stack trace ---
10-17 10:36:34.115 E/mono-rt (31518): at (wrapper dynamic-method) System.Object:585983a8-79f2-48a3-ac33-5b4c905219f1 (intptr,intptr,intptr,intptr,int,long)
10-17 10:36:34.115 E/mono-rt (31518): at (wrapper native-to-managed) System.Object:585983a8-79f2-48a3-ac33-5b4c905219f1 (intptr,intptr,intptr,intptr,int,long)
In mgmain JNI_OnLoad

As the stack trace indicates and the path you have posted in the comments shows. You have installed the PCL version into the platform specific projects. Which is why it throws the PlatformNotSupportedException exception you are getting.
Try reinstalling the NuGet in your platform specific projects. Alternatively you can manually change the reference to point at:
packages\Realm.0.78.1\lib\MonoAndroid44\Realm.dll
You shouldn't have any reference to the portable folder in your platform specific project.

I had a similar problem using Xamarin.Forms 3.4.0.1008975 with Realm 4.0.1
Unhandled Exception: System.TypeInitializationException: The type
initializer for 'Realms.SharedRealmHandle' threw an exception.
occurred
The solution was to completely uninstall the nuget Realm package from all projects in the solution and reinstall Realm back again. Also make sure that you have the FodyWeaver.xml file in all projects.

Related

ThreadPool or Timers tasks are not waiting properly

After updating Android's Support Libraries (v28.0+) to get targeted with monoandroid90, the app crashes sometimes with the stack trace I provided bellow. If there are breakpoints active this won't happen.
Different versions of Xamarin.Android were tested, the current one I'm using is the latest 9.4 that comes with the default vs19. I was not able to reproduce this on a fresh install of the vs17 with the default XA that comes with it (9.1.7.0)
The following stack trace shows the current problem I'm facing.
at System.Threading._ThreadPoolWaitCallback.PerformWaitCallback () <0x00007>
at (wrapper runtime-invoke) <Module>.runtime_invoke_bool (object,intptr,intptr,intptr) [0x0002b] in <ff07eae8184a40a08e79049bbcb31a0e>:0
"Finalizer"08-06 16:26:25.748 E/mono (11487): Full thread dump:
"Thread Pool Worker" at <unknown> <0xffffffff>
at System.Threading._ThreadPoolWaitCallback.PerformWaitCallback () <0x00007>
at (wrapper runtime-invoke) <Module>.runtime_invoke_bool (object,intptr,intptr,intptr) [0x0002b] in <ff07eae8184a40a08e79049bbcb31a0e>:0
"Debugger agent"
"Timer-Scheduler" at <unknown> <0xffffffff>
at (wrapper managed-to-native) System.Threading.WaitHandle.Wait_internal (intptr*,int,bool,int) <0x00007>
at System.Threading.WaitHandle.WaitOneNative (System.Runtime.InteropServices.SafeHandle,uint,bool,bool) [0x0001f] in <ff07eae8184a40a08e79049bbcb31a0e>:0
at System.Threading.WaitHandle.InternalWaitOne (System.Runtime.InteropServices.SafeHandle,long,bool,bool) [0x00019] in <ff07eae8184a40a08e79049bbcb31a0e>:0
at System.Threading.WaitHandle.WaitOne (long,bool) [0x00010] in <ff07eae8184a40a08e79049bbcb31a0e>:0
at System.Threading.WaitHandle.WaitOne (int,bool) [0x0001d] in <ff07eae8184a40a08e79049bbcb31a0e>:0
at System.Threading.WaitHandle.WaitOne (int) [0x00003] in <ff07eae8184a40a08e79049bbcb31a0e>:0
at System.Threading.Timer/Scheduler.SchedulerThread () [0x00043] in <ff07eae8184a40a08e79049bbcb31a0e>:0
at System.Threading.ThreadHelper.ThreadStart_Context (object) [0x0001f] in <ff07eae8184a40a08e79049bbcb31a0e>:0
at System.Threading.ExecutionContext.RunInternal (System.Threading.ExecutionContext,System.Threading.ContextCallback,object,bool) [0x00073] in <ff07eae8184a40a08e79049bbcb31a0e>:0
at System.Threading.ExecutionContext.Run (System.Threading.ExecutionContext,System.Threading.ContextCallback,object,bool) [0x00004] in <ff07eae8184a40a08e79049bbcb31a0e>:0
at System.Threading.ExecutionContext.Run (System.Threading.ExecutionContext,System.Threading.ContextCallback,object) [0x0002f] in <ff07eae8184a40a08e79049bbcb31a0e>:0
at System.Threading.ThreadHelper.ThreadStart () [0x00014] in <ff07eae8184a40a08e79049bbcb31a0e>:0
at (wrapper runtime-invoke) object.runtime_invoke_void__this__ (object,intptr,intptr,intptr) [0x00067] in <ff07eae8184a40a08e79049bbcb31a0e>:0
"<unnamed thread>"
08-06 16:26:35.755 I/libc (11487): Requested dump for tid 11487 (ler.challengeme)
Anybody else has ever faced this issue and is aware of a possible solution?

App crashes in release mode and not in debug mode - Xamarin Forms

I am building a cross platform app and i want to release it to testers, but it doesn't work when i am deploying it in release mode. As far as exceptions go i do not get any. As stated in the question it works in debug mode. The app just goes to splashscreen and crashes. I ran the original app through test fairy and got this exception:
java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1099)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1283)
... 2 more
Caused by: md52ce486a14f4bcd95899665e9d932190b.JavaProxyThrowable: System.IO.FileNotFoundException: Could not load file or assembly '<Censored: Name of forms class library>.dll' or one of its dependencies. The system cannot find the file specified.
File name: '<Censored: Name of forms class library>.dll'
at System.AppDomain.Load (System.Reflection.AssemblyName assemblyRef, System.Security.Policy.Evidence assemblySecurity) [0x00000] in :0
at System.AppDomain.Load (System.Reflection.AssemblyName assemblyRef) [0x00000] in :0
at (wrapper remoting-invoke-with-check) System.AppDomain:Load (System.Reflection.AssemblyName)
at System.Reflection.Assembly.Load (System.Reflection.AssemblyName assemblyRef) [0x00000] in :0
at Xamarin.Forms.Xaml.XamlParser.GetElementType (Xamarin.Forms.Xaml.XmlType xmlType, IXmlLineInfo xmlInfo, System.Reflection.Assembly currentAssembly, Xamarin.Forms.Xaml.XamlParseException& exception) [0x00000] in :0
at (wrapper delegate-invoke) :invoke_Type_XmlType_IXmlLineInfo_Assembly_XamlParseException& (Xamarin.Forms.Xaml.XmlType,System.Xml.IXmlLineInfo,System.Reflection.Assembly,Xamarin.Forms.Xaml.XamlParseException&)
at Xamarin.Forms.Xaml.XamlTypeResolver.Resolve (System.String qualifiedTypeName, IServiceProvider serviceProvider, Xamarin.Forms.Xaml.XamlParseException& exception) [0x00000] in :0
at Xamarin.Forms.Xaml.XamlTypeResolver.TryResolve (System.String qualifiedTypeName, System.Type& type) [0x00000] in :0
at Xamarin.Forms.Xaml.ExpandMarkupsVisitor+MarkupExpansionParser.Parse (System.String match, System.String& remaining, IServiceProvider serviceProvider) [0x00000] in :0
at Xamarin.Forms.Xaml.ExpandMarkupsVisitor.ParseExpression (System.String& expression, IXmlNamespaceResolver nsResolver, IXmlLineInfo xmlLineInfo, INode node, INode parentNode) [0x00000] in :0
at Xamarin.Forms.Xaml.ExpandMarkupsVisitor.Visit (Xamarin.Forms.Xaml.MarkupNode markupnode, INode parentNode) [0x00000] in :0
at Xamarin.Forms.Xaml.MarkupNode.Accept (IXamlNodeVisitor visitor, INode parentNode) [0x00000] in :0
at Xamarin.Forms.Xaml.ElementNode.Accept (IXamlNodeVisitor visitor, INode parentNode) [0x00000] in :0
at Xamarin.Forms.Xaml.ElementNode.Accept (IXamlNodeVisitor visitor, INode parentNode) [0x00000] in :0
at Xamarin.Forms.Xaml.RootNode.Accept (IXamlNodeVisitor visitor, INode parentNode) [0x00000] in :0
at Xamarin.Forms.Xaml.XamlLoader.Load (Xamarin.Forms.BindableObject view, System.String xaml) [0x00000] in :0
at Xamarin.Forms.Xaml.XamlLoader.Load (Xamarin.Forms.BindableObject view, System.Type callingType) [0x00000] in :0
at Xamarin.Forms.Xaml.Extensions.LoadFromXaml[LoginPage] (<Censored>.Login.LoginPage view, System.Type callingType) [0x00000] in :0
at <Censored>.Login.LoginPage.InitializeComponent () [0x00000] in :0
at <Censored>.Login.LoginPage..ctor () [0x00000] in :0
at <Censored>.App.b__0 () [0x00000] in :0
at <Censored>.ViewFactory.Resolve[LoginViewModel] (<Censored>.Login.LoginViewModel viewModel) [0x00000] in :0
at <Censored>.App..ctor () [0x00000] in :0
at md5b406f03a919343acc4f3b337a44e1248.MainActivity.n_onCreate(Native Method)
at md5b406f03a919343acc4f3b337a44e1248.MainActivity.onCreate(MainActivity.java:28)
at android.app.Activity.performCreate(Activity.java:5458)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1093)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2376)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2470)
at android.app.ActivityThread.access$900(ActivityThread.java:174)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1307)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:146)
at android.app.ActivityThread.main(ActivityThread.java:5593)
... 5 more
I cannot show you the source code, but i have reproduced the error in a new test solution.
Here is a link to the repository with the test project. It is just a project using MVVM with Xamarin Forms.
Fixed it by manually deleting all obj folders and all bin folders in the entire solution.
Edit: Came back again and now this fix does not work!
If your solution works in Debug mode, but not in Release mode, it might be an issue with the Linker.
Right Click on your specific project (not Solution) -> Android Options -> Linker -> Choose "None" in Linking. This will include all dlls in the Release Library.

Chat Server Mysql error

When i try to start the server i got everytime the same error.
i searched here for a solution and found something that i have to edit my connection string. After this im get the same error again
Sorry for my bad english
`RRChatServer.exe
Unhandled Exception: System.EntryPointNotFoundException:
CreateSemaphore at (wrapper managed-to-native)
MySql.Data.Common.Semaphore:CreateSemaphore
(MySql.Data.Common.SECURITY_ATTRIBUTES&,int,int,string) at
MySql.Data.Common.Semaphore..ctor (Int32 initialCount, Int32
maximumCount) [0x00000] in :0 at (wrapper
remoting-invoke-with-check) MySql.Data.Common.Semaphore:.ctor
(int,int) at MySql.Data.MySqlClient.MySqlPool..ctor
(MySql.Data.MySqlClient.MySqlConnectionString settings) [0x00000] in
:0 at
MySql.Data.MySqlClient.MySqlPoolManager.GetPool
(MySql.Data.MySqlClient.MySqlConnectionString settings) [0x00000] in
:0 at MySql.Data.MySqlClient.MySqlConnection.Open
() [0x00000] in :0 [ERROR] FATAL UNHANDLED
EXCEPTION: System.EntryPointNotFoundException: CreateSemaphore at
(wrapper managed-to-native)
MySql.Data.Common.Semaphore:CreateSemaphore
(MySql.Data.Common.SECURITY_ATTRIBUTES&,int,int,string) at
MySql.Data.Common.Semaphore..ctor (Int32 initialCount, Int32
maximumCount) [0x00000] in :0 at (wrapper
remoting-invoke-with-check) MySql.Data.Common.Semaphore:.ctor
(int,int) at MySql.Data.MySqlClient.MySqlPool..ctor
(MySql.Data.MySqlClient.MySqlConnectionString settings) [0x00000] in
:0 at
MySql.Data.MySqlClient.MySqlPoolManager.GetPool
(MySql.Data.MySqlClient.MySqlConnectionString settings) [0x00000] in
:0 at MySql.Data.MySqlClient.MySqlConnection.Open
() [0x00000] in :0`

OnPropertyChanged throws exception on android in xamarin.forms app

I'm making an android app with Xamarin.Forms. My iOS app is already finished and released.
My android version will not stop throwing multiple exceptions.
The first exception is a NullReferenceException. This breaks on the following code snipped:
handler(this, new PropertyChangedEventArgs(propertyName));
This is inside my OnPropertyChanged method in a custom NotifyBase class I use for my models.
(Also failing if i remove all but this line from the method.)
The debug output just tells me this:
System.NullReferenceException: Object reference not set to an instance of an object
An unhandled exception occured.
Exception:
This is followed by a TargetInvocationException giving this stack trace:
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation.
07-16 17:37:47.916 I/MonoDroid(27212): UNHANDLED EXCEPTION: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.NullReferenceException: Object reference not set to an instance of an object
07-16 17:37:47.916 I/MonoDroid(27212):07-16 17:37:47.916 I/MonoDroid(27212): at Xamarin.Forms.Forms+AndroidPlatformServices.BeginInvokeOnMainThread (System.Action action) [0x00000] in <filename unknown>:0
07-16 17:37:47.916 I/MonoDroid(27212): at Xamarin.Forms.Device.BeginInvokeOnMainThread (System.Action action) [0x00000] in <filename unknown>:0
07-16 17:37:47.916 I/MonoDroid(27212): at Xamarin.Forms.BindingExpression+BindingExpressionPart.PropertyChanged (System.Object sender, System.ComponentModel.PropertyChangedEventArgs args) [0x00000] in <filename unknown>:0
07-16 17:37:47.916 I/MonoDroid(27212): at (wrapper delegate-invoke) <Module>:invoke_void__this___object_PropertyChangedEventArgs (object,System.ComponentModel.PropertyChangedEventArgs)
07-16 17:37:47.916 I/MonoDroid(27212): at (wrapper delegate-invoke) <Module>:invoke_void__this___object_PropertyChangedEventArgs (object,System.ComponentModel.PropertyChangedEventArgs)
07-16 17:37:47.916 I/MonoDroid(27212): at TransMission.Mobile.Helper.NotifyBase.OnPropertyChanged (System.String propertyName) [0x00087] in c:\Users\Frederik.TECNO\Documents\Visual Studio 2012\Projects\TransMission\TransMission.Mobile\TransMission.Mobile\Helper\NotifyBase.cs:68
07-16 17:37:47.916 I/MonoDroid(27212): at TransMission.Mobile.Helper.NotifyBase.SetField[DateTime] (System.DateTime& field, DateTime value, System.String propertyName) [0x000a2] in c:\Users\Frederik.TECNO\Documents\Visual Studio 2012\Projects\TransMission\TransMission.Mobile\TransMission.Mobile\Helper\NotifyBase.cs:102
07-16 17:37:47.916 I/MonoDroid(27212): at TransMission.Mobile.Core.TransMissionCore.set_Date (DateTime value) [0x00001] in c:\Users\Frederik.TECNO\Documents\Visual Studio 2012\Projects\TransMission\TransMission.Mobile\TransMission.Mobile\Core\TransMissionCore.cs:275
07-16 17:37:47.916 I/MonoDroid(27212): at (wrapper managed-to-native) System.Reflection.MonoMethod:InternalInvoke (System.Reflection.MonoMethod,object,object[],System.Exception&)
07-16 17:37:47.916 I/MonoDroid(27212): at System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00000] in <filename unknown>:0
07-16 17:37:47.916 I/MonoDroid(27212): --- End of inner exception stack trace ---
07-16 17:37:47.916 I/MonoDroid(27212): at System.Reflection.MonoMethod.Invoke (object,System.Reflection.BindingFlags,System.Reflection.Binder,object[],System.Globalization.CultureInfo) <IL 0x00062, 0x0033c>
07-16 17:37:47.916 I/MonoDroid(27212): at Xamarin.Forms.BindingExpression.ApplyCore (object,Xamarin.Forms.BindableObject,Xamarin.Forms.BindableProperty,bool) <IL07-16 17:37:47.916 I/MonoDroid(27212): at System.Reflection.MethodBase.Invoke (object,object[]) <IL 0x00006, 0x0008f>
07-16 17:37:47.916 I/MonoDroid(27212): at Xamarin.Forms.BindingExpression.ApplyCore (object,Xamarin.Forms.BindableObject,Xamarin.Forms.BindableProperty,bool) <IL 0x00295, 0x0162f>
07-16 17:37:47.916 I/MonoDroid(27212): at Xamarin.Forms.BindingExpression.Apply (bool) <IL 0x00041, 0x0018b>
07-16 17:37:47.916 I/MonoDroid(27212): at Xamarin.Forms.Binding.Apply (bool) <IL 0x00027, 0x00113>
07-16 17:37:47.916 I/MonoDroid(27212): at Xamarin.Forms.BindableObject/<>c__DisplayClass1.<SetValueCore>b__0 () <IL 0x00100, 0x00493>
07-16 17:37:47.916 I/MonoDroid(27212): at Xamarin.Forms.BindableObject.SetValueCore (Xamarin.Forms.BindableProperty,object,bool,bool,bool) <IL 0x001b4, 0x009d3>
07-16 17:37:47.916 I/MonoDroid(27212): at Xamarin.Forms.BindingExpression.ApplyCore (object,Xamarin.Forms.BindableObject,Xamarin.Forms.BindableProperty,bool) <IL 0x001f1, 0x011db>
07-16 17:37:47.916 I/MonoDroid(27212): at Xamarin.Forms.BindingExpression.Apply (object,Xamarin.Forms.BindableObject,Xamarin.Forms.BindableProperty) <IL 0x0007e, 0x003bf>
07-16 17:37:47.916 I/MonoDroid(27212): at Xamarin.Forms.Binding.Apply (object,Xamarin.Forms.BindableObject,Xamarin.Forms.BindableProperty) <IL 0x0004d, 0x00237>
07-16 17:37:47.916 I/MonoDroid(27212): at Xamarin.Forms.BindableObject.ApplyBindings (object) <IL 0x0003a, 0x002af>
07-16 17:37:47.916 I/MonoDroid(27212): at Xamarin.Forms.BindableObject.SetInheritedBindingContext (Xamarin.Forms.BindableObject,object) <IL 0x00056, 0x0029b>
07-16 17:37:47.916 I/MonoDroid(27212): at Xamarin.Forms.Element.OnBindingContextChanged () <IL 0x0001c, 0x00157>
07-16 17:37:47.916 I/MonoDroid(27212): at Xamarin.Forms.View.OnBindingContextChanged () <IL 0x0003b, 0x002a3>
07-16 17:37:47.916 I/MonoDroid(27212): at Xamarin.Forms.BindableObject.SetInheritedBindingContext (Xamarin.Forms.BindableObject,object) <IL 0x0005c, 0x002bf>
07-16 17:37:47.916 I/MonoDroid(27212): at Xamarin.Forms.Element.set_Parent (Xamarin.Forms.Element) <IL 0x00020, 0x00107>
07-16 17:37:47.916 I/MonoDroid(27212): at Xamarin.Forms.Element.OnChildAdded (Xamarin.Forms.Element) <IL 0x00002, 0x00053>
07-16 17:37:47.916 I/MonoDroid(27212): at Xamarin.Forms.Page.OnInternalAdded (Xamarin.Forms.VisualElement) <IL 0x00015, 0x000bf>
07-16 17:37:47.916 I/MonoDroid(27212): at Xamarin.Forms.Page.InternalChildrenOnCollectionChanged (object,System.Collections.Specialized.NotifyCollectionC
Unhandled Exception:
Again followed by a TargetInvocationException giving this stack trace:
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation.
07-16 17:41:19.182 E/mono (27212):
07-16 17:41:19.182 E/mono (27212): Unhandled Exception:
07-16 17:41:19.182 E/mono (27212): at (wrapper delegate-invoke) <Module>:invoke_void__this___object_PropertyChangedEventArgs (object,System.Compon07-16 17:41:19.182 E/mono (27212): System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.NullReferenceException: Object reference not set to an instance of an object
07-16 17:41:19.182 E/mono (27212): at Xamarin.Forms.Forms+AndroidPlatformServices.BeginInvokeOnMainThread (System.Action action) [0x00000] in <filename unknown>:0
07-16 17:41:19.182 E/mono (27212): at Xamarin.Forms.Device.BeginInvokeOnMainThread (System.Action action) [0x00000] in <filename unknown>:0
07-16 17:41:19.182 E/mono (27212): at Xamarin.Forms.BindingExpression+BindingExpressionPart.PropertyChanged (System.Object sender, System.ComponentModel.PropertyChangedEventArgs args) [0x00000] in <filename unknown>:0
07-16 17:41:19.182 E/mono (27212): at (wrapper delegate-invoke) <Module>:invoke_void__this___object_PropertyChangedEventArgs (object,System.ComponentModel.PropertyChangedEventArgs)
07-16 17:41:19.182 E/mono (27212): at (wrapper delegate-invoke) <Module>:invoke_void__this___object_PropertyChangedEventArgs (object,System.ComponentModel.PropertyChangedEventArgs)
07-16 17:41:19.182 E/mono (27212): at TransMission.Mobile.Helper.NotifyBase.OnPropertyChanged (System.String propertyName
07-16 17:41:19.182 E/mono-rt (27212): [ERROR] FATAL UNHANDLED EXCEPTION: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.NullReferenceException: Object reference not set to an instance of an object
07-16 17:41:19.182 E/mono-rt (27212): at Xamarin.Forms.Forms+AndroidPlatformServices.BeginInvokeOnMainThread (System.Action action) [0x00000] in <filename unknown>:0
07-16 17:41:19.182 E/mono-rt (27212): at Xamarin.Forms.Device.BeginInvokeOnMainThread (System.Action action) [0x00000] in <filename unknown>:0
07-16 17:41:19.182 E/mono-rt (27212): at Xamarin.Forms.BindingExpression+BindingExpressionPart.PropertyChanged (System.Object sender, System.ComponentModel.PropertyChangedEventArgs args) [0x00000] in <filename unknown>:0
07-16 17:41:19.182 E/mono-rt (27212): at (wrapper delegate-invoke) <Module>:invoke_void__this___object_PropertyChangedEventArgs (object,System.ComponentModel.PropertyChangedEventArgs)
07-16 17:41:19.182 E/mono-rt (27212): at (wrapper delegate-invoke) <Module>:invoke_void__this___object_PropertyChangedEventArgs (object,System.ComponentModel.PropertyChangedEventArgs)
07-16 17:41:19.182 E/mono-rt (27212): at TransMission.Mobile.Helper.NotifyBase.OnPropertyChanged (System.String
Das Programm "Mono" wurde mit Code 0 (0x0) beendet.
As my debug output states this seems to happen for a DateTime property that is set to what seems to be a min value for the DatePicker:
07-16 17:32:45.761 I/mono-stdout(27212): DEBUG - Changing value from '01.01.0001 00:00:00' to '01.01.1900 00:00:00'.
07-16 17:32:45.771 I/mono-stdout(27212): DEBUG - Raising PropertyChanged for: 'TransMissionCore.Date'.
My codes works perfectly on iOS. But on Android this is a show stopper.
I tried my app with the latest version of Xamarin.Forms (1.2.1.6229) and with 1.1.1.6206 but this makes no difference.
Is there some kind of workaround? Or am i making a mistake?
Please give advice.
This is fixed in the latest release of xamarin forms.
I did not spend enough attention to the stack trace of the exception in the latest version.
I thought the stack traces are equal but they differ in some parts
This seems to have another source and comes from another part of my app.

monogame content load file not found exception

The following post looks similar to my issue, but ultimately it doesn't look exactly the same down to all the details, so I am calling that out to prevent claims that its the same.
I am following this monogame tutorial (currently on step 2) in Xamarin Studio:
When I run the resulting monogame app at the end of step 2 I get the following exception (pasted at the end) when I hit the line of code that attempts to load the player content. I have the player content file setup correctly AFAIK, its copied to the output folder, but I am assuming that its somehow not deployed correctly to the Andriod Virtual Machine (AVM), which I have not been able to figure out how to examine the deployed contents. I pulled up Android Monitor to explore the AVM and try to figure out where things are, but I haven't had any luck figuring that out... The file not found exception seems to be clear that what's running on the AVM isn't finding the content file... but I can't figure out how to correct that.
Any help would be appreciated, thanks!
The sources and project that I am having this issue with are here
The exception I am seeing is the following:
[MonoDroid] UNHANDLED EXCEPTION: Microsoft.Xna.Framework.Content.ContentLoadException: Could not load Graphics\player asset as a non-content file! ---> Microsoft.Xna.Framework.Content.ContentLoadException: Opening stream error. ---> Java.IO.FileNotFoundException: Exception of type 'Java.IO.FileNotFoundException' was thrown. [MonoDroid] at Android.Runtime.JNIEnv.CallObjectMethod (IntPtr jobject, IntPtr jmethod, Android.Runtime.JValue[] parms) [0x00000] in :0 [MonoDroid] at Android.Content.Res.AssetManager.Open (System.String fileName) [0x00000] in :0 [MonoDroid] at Microsoft.Xna.Framework.TitleContainer.OpenStream (System.String name) [0x00000] in :0 [MonoDroid] at Microsoft.Xna.Framework.Content.ContentManager.OpenStream (System.String assetName) [0x00000] in :0 [MonoDroid] --- End of managed exception stack trace --- [MonoDroid] java.io.FileNotFoundException: Content/Graphics/player.xnb [MonoDroid] at android.content.res.AssetManager.openAsset(Native Method) [MonoDroid] at android.content.res.AssetManager.open(AssetManager.java:315) [MonoDroid] at android.content.res.AssetManager.open(AssetManager.java:289) [MonoDroid] at mono.java.lang.RunnableImplementor.n_run(Native Method) [MonoDroid] at mono.java.lang.RunnableImplementor.run(RunnableImplementor.java:29) [MonoDroid] at android.os.Handler.handleCallback(Handler.java:605) [MonoDroid] at android.os.Handler.dispatchMessage(Handler.java:92) [MonoDroid] at android.os.Looper.loop(Looper.java:137) [MonoDroid] at android.app.ActivityThread.main(ActivityThread.java:4424) [MonoDroid] at java.lang.reflect.Method.invokeNative(Native Method) [MonoDroid] at java.lang.reflect.Method.invoke(Method.java:511) [MonoDroid] at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784) [MonoDroid] at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551) [MonoDroid] at dalvik.system.NativeStart.main(Native Method) [MonoDroid] [MonoDroid] --- End of inner exception stack trace --- [MonoDroid] at Microsoft.Xna.Framework.Content.ContentManager.OpenStream (System.String assetName) [0x00000] in :0 [MonoDroid] at Microsoft.Xna.Framework.Content.ContentManager.ReadAsset[Texture2D] (System.String assetName, System.Action1 recordDisposableObject) [0x00000] in :0
[MonoDroid] --- End of inner exception stack trace ---
[MonoDroid] at Microsoft.Xna.Framework.Content.ContentManager.ReadAsset (string,System.Action1) <0x0042c> [MonoDroid] at Microsoft.Xna.Framework.Content.ContentManager.Load (string) <0x000c3> [MonoDroid] at SampleShooter.Game1.LoadContent () <0x0018b> [MonoDroid] at Microsoft.Xna.Framework.Game.Initialize () <0x0023f> [MonoDroid] at SampleShooter.Game1.Initialize () <0x00037> [MonoDroid] at Microsoft.Xna.Framework.Game.DoInitialize () <0x00037> [MonoDroid] at Microsoft.Xna.Framework.AndroidGamePlatform.BeforeUpdate (Microsoft.Xna.Framework.GameTime) <0x0002b> [MonoDroid] at Microsoft.Xna.Framework.Game.DoUpdate (Microsoft.Xna.Framework.GameTime) <0x0002f> [MonoDroid] at Microsoft.Xna.Framework.Game.Tick () <0x00493> [MonoDroid] at Microsoft.Xna.Framework.AndroidGameWindow.OnUpdateFrame (OpenTK.FrameEventArgs) <0x000a7> [MonoDroid] at OpenTK.Platform.Android.AndroidGameView.UpdateFrameInternal (OpenTK.FrameEventArgs) <0x00033> [MonoDroid] at OpenTK.Platform.Android.AndroidGameView.RunIteration (System.Threading.CancellationToken) <0x001c3> [MonoDroid] at OpenTK.Platform.Android.AndroidGameView/c__AnonStorey0.<>m__2 (object) <0x00027> [MonoDroid] at Android.App.SyncContext/c__AnonStorey2F.<>m__1A () <0x00023> [MonoDroid] at Java.Lang.Thread/RunnableImplementor.Run () <0x0003f> [MonoDroid] at Java.Lang.IRunnableInvoker.n_Run (intptr,intptr) <0x00037> [MonoDroid] at (wrapper dynamic-method) object.e85befee-f4e0-4f15-9232-77621081c7b5 (intptr,intptr) <0x0003b> [mono] [mono] Unhandled Exception: [mono] Microsoft.Xna.Framework.Content.ContentLoadException: Could not load Graphics\player asset as a non-content file! ---> Microsoft.Xna.Framework.Content.ContentLoadException: Opening stream error. ---> Java.IO.FileNotFoundException: Exception of type 'Java.IO.FileNotFoundException' was thrown. [mono] at Android.Runtime.JNIEnv.CallObjectMethod (IntPtr jobject, IntPtr jmethod, Android.Runtime.JValue[] parms) [0x00000] in :0 [mono] at Android.Content.Res.AssetManager.Open (System.String fileName) [0x00000] in :0 [mono] at Microsoft.Xna.Framework.TitleContainer.OpenStream (System.String name) [0x00000] in :0 [mono] at Microsoft.Xna.Framework.Content.ContentManager.OpenStream (System.String assetName) [0x00000] in :0 [mono] --- End of managed exception stack trace --- [mono] java.io.FileNotFoundException: Content/Graphics/player.xnb [mono] at android.content.res.AssetManager.openAsset(Native Method) [mono] at android.content.res.AssetManager.open(AssetManager.ja [mono] [ERROR] FATAL UNHANDLED EXCEPTION: Microsoft.Xna.Framework.Content.ContentLoadException: Could not load Graphics\player asset as a non-content file! ---> Microsoft.Xna.Framework.Content.ContentLoadException: Opening stream error. ---> Java.IO.FileNotFoundException: Exception of type 'Java.IO.FileNotFoundException' was thrown. [mono] at Android.Runtime.JNIEnv.CallObjectMethod (IntPtr jobject, IntPtr jmethod, Android.Runtime.JValue[] parms) [0x00000] in :0 [mono] at Android.Content.Res.AssetManager.Open (System.String fileName) [0x00000] in :0 [mono] at Microsoft.Xna.Framework.TitleContainer.OpenStream (System.String name) [0x00000] in :0 [mono] at Microsoft.Xna.Framework.Content.ContentManager.OpenStream (System.String assetName) [0x00000] in :0 [mono] --- End of managed exception stack trace --- [mono] java.io.FileNotFoundException: Content/Graphics/player.xnb [mono] at android.content.res.AssetManager.openAsset(Native Method) [mono] at android.content.res.AssetManager.open(As
So I finally figured out that I needed to mark the XNB file as an AndroidAsset for the build action, and not Content as the example stated. Since the example I am following is aimed at Windows Mobile development this makes sense since the file would normally be marked as content for a Windows application, whereas for Android these files need to be marked as AndriodAsset in order for XNA to be able to access the raw content data, regardless of if the file is in a content or asset folder. The content manager's root folder by default is "Content", so you need to add the file there and mark it as an asset, not content...
Content for an android monogame project should be added to the project in the Assets/Content folder as built .xnb files rather than just copied to the output directory

Categories

Resources