By default in my xamarin forms app I have
AppCompatDelegate.DefaultNightMode =AppCompatDelegate.ModeNightNo;
But when I start it in dark mode I get the following exception
enter image description here,
in Xamarin.Forms.Platform.Android\PlatformConfigurationExtensions.cs
System.NullReferenceException:'Object reference not set to an instance of an object.'
Stacktrace:
at Xamarin.Forms.Platform.Android.PlatformConfigurationExtensions.OnThisPlatform[T] (T element) [0x00000]
in D:\a\1\s\Xamarin.Forms.Platform.Android\PlatformConfigurationExtensions.cs:8
at Xamarin.Forms.Platform.Android.AppCompat.FragmentContainer.OnResume () [0x00007]
in D:\a\1\s\Xamarin.Forms.Platform.Android\AppCompat\FragmentContainer.cs:126
at AndroidX.Fragment.App.Fragment.n_OnResume (System.IntPtr jnienv, System.IntPtr native__this) [0x00008]
in D:\a\1\s\generated\androidx.fragment.fragment\obj\Release\monoandroid9.0\generated\src\AndroidX.Fragment.App.Fragment.cs:2548
at (wrapper dynamic-method) Android.Runtime.DynamicMethodNameCounter.115(intptr,intptr)
It only happens in dark mode, in light mode it init normally.
I was trying to debug but all the threads at that moment are executing external code
Related
I am interested in Xamarin and I search, how I can take a photo from camera without device's native camera application. And I found Camera2 API, then I search sample app and I found this sample app: https://learn.microsoft.com/en-us/samples/xamarin/monodroid-samples/android50-camera2basic/
It worked very well when I tried it in the foreground but it gives an error when I put it in the background.
How can I get it running in the background?
Camera2BasicFragment.cs codes: https://paste.ubuntu.com/p/CqDkyMx8qW/
Exceptions:
Exception image 1
Exception image 2
Exception Text:
{Java.Lang.IllegalStateException: CameraDevice was already closed at Java.Interop.JniEnvironment+InstanceMethods.CallIntMethod (Java.Interop.JniObjectReference instance, Java.Interop.JniMethodInfo method, Java.Interop.JniArgumentValue* args) [0x0006e] in <dac4c5a4b77f4e61a5e6d9d3050dfb9f>:0 at Java.Interop.JniPeerMembers+JniInstanceMethods.InvokeAbstractInt32Method (System.String encodedMember, Java.Interop.IJavaPeerable self, Java.Interop.JniArgumentValue* parameters) [0x00014] in <dac4c5a4b77f4e61a5e6d9d3050dfb9f>:0 at Android.Hardware.Camera2.CameraCaptureSessionInvoker.Capture (Android.Hardware.Camera2.CaptureRequest request, Android.Hardware.Camera2.CameraCaptureSession+CaptureCallback listener, Android.OS.Handler handler) [0x0006e] in /Users/builder/azdo/_work/204/s/xamarin-android/src/Mono.Android/obj/Release/monoandroid10/android-27/mcw/Android.Hardware.Camera2.CameraCaptureSession.cs:969 at Camera2Basic.Camera2BasicFragment.LockFocus () [0x00020] in C:\Users\Harun\Desktop\x\Camera2Basic\Camera2BasicFragment.cs:576 at Camera2Basic.Camera2BasicFragment.TakePicture () [0x00001] in C:\Users\Harun\Desktop\x\Camera2Basic\Camera2BasicFragment.cs:563 at Camera2Basic.Camera2BasicFragment.OnClick (Android.Views.View v) [0x00013] in C:\Users\Harun\Desktop\x\Camera2Basic\Camera2BasicFragment.cs:676 at Android.Views.View+IOnClickListenerInvoker.n_OnClick_Landroid_view_View_ (System.IntPtr jnienv, System.IntPtr native__this, System.IntPtr native_v) [0x00010] in /Users/builder/azdo/_work/204/s/xamarin-android/src/Mono.Android/obj/Release/monoandroid10/android-27/mcw/Android.Views.View.cs:2176 at (wrapper dynamic-method) Android.Runtime.DynamicMethodNameCounter.19(intptr,intptr,intptr) --- End of managed Java.Lang.IllegalStateException stack trace ---java.lang.IllegalStateException: CameraDevice was already closed at android.hardware.camera2.impl.CameraDeviceImpl.checkIfCameraClosedOrInError(CameraDeviceImpl.java:1997) at android.hardware.camera2.impl.CameraDeviceImpl.submitCaptureRequest(CameraDeviceImpl.java:844) at android.hardware.camera2.impl.CameraDeviceImpl.capture(CameraDeviceImpl.java:741) at android.hardware.camera2.impl.CameraCaptureSessionImpl.capture(CameraCaptureSessionImpl.java:179) at crc64b678081366886b9e.Camera2BasicFragment.n_onClick(Native Method) at crc64b678081366886b9e.Camera2BasicFragment.onClick(Camera2BasicFragment.java:77) at android.view.View.performClick(View.java:5721) at android.widget.TextView.performClick(TextView.java:10936) 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:739) at android.os.Handler.dispatchMessage(Handler.java:95) at android.os.Looper.loop(Looper.java:148) at android.app.ActivityThread.main(ActivityThread.java:7406) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)}
We developed a xamarin forms android app, it's working in some devices and crashing in some devices --> the app will open, after the splash screen appears it is crashing.
It happens on few samsung devices
We found one google console log.
android.runtime.JavaProxyThrowable: at SanSmart.App.OnInitialized () [0x00254] in <ce58e5be75db448fa7eb95f3f96a4a6d>:0
at System.Runtime.CompilerServices.AsyncMethodBuilderCore+<>c.<ThrowAsync>b__6_0 (System.Object state) [0x00000] in <3a61d48d66dd458fa0b64990b6c8f8cc>:0
at Android.App.SyncContext+<>c__DisplayClass2_0.<Post>b__0 () [0x00000] in <3921e1c40bf740cab0f47696b3ad1282>:0
at Java.Lang.Thread+RunnableImplementor.Run () [0x00008] in <3921e1c40bf740cab0f47696b3ad1282>:0
at Java.Lang.IRunnableInvoker.n_Run (System.IntPtr jnienv, System.IntPtr native__this) [0x00009] in <3921e1c40bf740cab0f47696b3ad1282>:0
at (wrapper dynamic-method) Android.Runtime.DynamicMethodNameCounter.36(intptr,intptr)
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:873)
at android.os.Handler.dispatchMessage (Handler.java:99)
at android.os.Looper.loop (Looper.java:214)
at android.app.ActivityThread.main (ActivityThread.java:6986)
at java.lang.reflect.Method.invoke (Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:1445)
I am working on an existing Xamarin iOS application with a PCL and uses MvvmCross for IoC and Databinding. Built on MvvmCross 3.1.1
The App looks like a TabControl App but it is buttons on the MainViewCotnroller giving the Tab feel to it. Views are declared in the Storyboard and in the MainViewController,
PrepareForSegue(UIStoryboardSegue segue, NSObject sender) method
is overridden to load the selected "Tab" View based on the Segue selected - like below
if (segue.Identifier == "FirstSegue")
{
var dest = segue.DestinationViewController as FirstView;
dest.Request = new MvxViewModelRequest<FirstViewModel>(null, null, new MvxRequestedBy());
foreach (UIView v in src.placeHolderView.Subviews)
{
v.RemoveFromSuperview();
}
dest.View.Frame = new CGRect(0f, 0f, w, h);
src.placeHolderView.Add(dest.View);
}
The App runs fine on iPhones with iOS 7.1 till 8.4.
Just before iOS 9 was released I did a test installation for the App on iPhone 6 with iOS 9.1 beta and the App crashed on loading. I retrieved the device logs (below) and analysed that the problem is in the guts of the MvvmCross ViewDidLoad method. I updated the latest SDKs (XCode 7, Xamarin.IOS 9.0) and followed instructions provided by Xamarin and compiled the App again using the latest SDKs same error. Updated the Nuget package reference for MvvmCross to 3.5.1 and still the same issue
The issues is there is a null reference at Line 44 in the 3.5 MvvMCross Source Code in GitHub
Note: This piece of code has not changed since 3.1 at least and 3.5.1 is the latest in the nuget for MvvmCross
Stack Trace below (App Names, Project Names changed for security reasons):
2015-09-21 11:06:26.991 MyApp[1210:60b] Unhandled managed exception:
Object reference not set to an instance of an object (System.NullReferenceException)
at Cirrious.CrossCore.Mvx.Resolve[IMvxViewModelLoader] () [0x00006] in <filename unknown>:0
at Cirrious.MvvmCross.Touch.Views.MvxViewControllerExtensionMethods.LoadViewModel (IMvxTouchView touchView) [0x00057] in <filename unknown>:0
at Cirrious.MvvmCross.Views.MvxViewExtensionMethods.OnViewCreate (IMvxView view, System.Func`1 viewModelLoader) [0x00012] in <filename unknown>:0
at Cirrious.MvvmCross.Touch.Views.MvxViewControllerExtensionMethods.OnViewCreate (IMvxTouchView touchView) [0x00001] in <filename unknown>:0
at Cirrious.MvvmCross.Touch.Views.MvxViewControllerAdapter.HandleViewDidLoadCalled (System.Object sender, System.EventArgs e) [0x00007] in <filename unknown>:0
at (wrapper delegate-invoke) <Module>:invoke_void_object_EventArgs (object,System.EventArgs)
at Cirrious.CrossCore.Core.MvxDelegateExtensionMethods.Raise (System.EventH
andler eventHandler, System.Object sender) [0x00004] in <filename unknown>:0
at Cirrious.CrossCore.Touch.Views.MvxEventSourceTableViewController.ViewDidLoad () [0x00006] in <filename unknown>:0
at MyProject.Touch.MostPurchasedView.ViewDidLoad () [0x00048] in d:\Working\Repo\MyApp\<MyProjectName>\MyProject.Touch\Views\OneOfTheView.cs:31
at (wrapper managed-to-native) ObjCRuntime.Messaging:IntPtr_objc_msgSendSuper (intptr,intptr)
at UIKit.UIViewController.get_View () [0x00030] in /Users/builder/data/lanes/2077/d230615b/source/maccore/src/build/ios/native/UIKit/UIViewController.g.cs:2632
at MyProject.Touch.HomeViewController.PrepareForSegue (UIKit.UIStoryboardSegue segue, Foundation.NSObject sender) [0x0016a] in d:\Working\Repo\MyApp\MyProject.Mobile\MyProject.Touch\HomeViewController.cs:335
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/2077/d230615b/source/maccore/src/UIKit/UIApplication.cs:74
at UIKit.UIApplication.Main (System.String[] args, System.String principalClassName, System.String delegateClassName) [0x0001c] in /Users/builder/data/lanes/2077/d230615b/source/maccore/src/UIKit/UIApplication.cs:57
at MyProject.Touch.Application.Main (System.String[] args) [0x00001] in d:\Working\Repo\MyApp\MyProject.Mobile\MyProject.Touch\Main.cs:16
2015-09-21 11:06:26.994 MyApp[1210:60b] critical: Stacktrace:
Native stacktrace:
.....
I tried the above with just calling the below in the View.cs:
public override void ViewDidLoad()
{
try
{
base.ViewDidLoad();
}
catch (Exception ex)
{
// throw a toast msg in the UI
}
}
I disabled all the base.ViewDidLoad() in all the View.cs files in the ViewDidLoad override methods to take it to the next level and the same problem but inside the constructor of MvxSimpleTableViewSource class
Device Log below:
Object reference not set to an instance of an object (System.NullReferenceException)
at Cirrious.CrossCore.Mvx.TryResolve[IMvxTouchSystem] (IMvxTouchSystem& service) [0x00006] in <filename unknown>:0
at Cirrious.CrossCore.Touch.Platform.MvxIosMajorVersionChecker.ReadIsIosVersionOrHigher (Int32 target, Boolean defaultValue) [0x00000] in <filename unknown>:0
at Cirrious.CrossCore.Touch.Platform.MvxIosMajorVersionChecker..ctor (Int32 major, Boolean defaultValue) [0x00006] in <filename unknown>:0
at Cirrious.MvvmCross.Binding.Touch.Views.MvxSimpleTableViewSource..ctor (UIKit.UITableView tableView, System.String nibName, System.String cellIdentifier, Foundation.NSBundle bundle) [0x00000] in <filename unknown>:0
at MyProject.Touch.MostPurchasedView.ViewDidLoad () [0x00059] in d:\Working\Repo\MyApp\MyProject.Mobile\MyProject.Touch\Views\OneOfTheView.cs:42
at (wrapper managed-to-native) ObjCRuntime.Messaging:IntPtr_objc_msgSendSuper (intptr,intptr)
at UIKit.UIViewController.get_View () [0x00030] in /Users/builder/data/lanes/2077/d230615b/source/maccore/src/build/ios/native/UIKit/UIViewController.g.cs:2632
at MyProject.Touch.HomeViewController.PrepareForSegue (UIKit.UIStoryboardSegue segue, Foundation.NSObject sender) [0x0016a] in d:\Working\Repo\MyApp\MyProject.Mobile\MyProject.Touch\HomeViewController.cs:343
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/2077/d230615b/source/maccore/src/UIKit/UIApplication.cs:74
at UIKit.UIApplication.Main (System.String[] args, System.String principalClassName, System.String delegateClassName) [0x0001c] in /Users/builder/data/lanes/2077/d230615b/source/maccore/src/UIKit/UIApplication.cs:57
at MyProject.Touch.Application.Main (System.String[] args) [0x00001] in d:\Working\Repo\MyApp\MyProject.Mobile\MyProject.Touch\Main.cs:16
In short :
Only in iOS 9.1, MvvmCross 3.1.1 AND MvvmCross 3.5.1 has a NullReference Issue in line 44 of the MvxViewControllerExtensionMethods class which gets called during ViewDidLoad but works well with iOS 8.4 and below
I am just getting familiar with MvvmCross framework and unsure whether it is an issue with MvvmCross and iOS 9.
Has anyone come across this issue? Any help on this would be appreciated.
Note: The MvvmCross samples work fine with iOS9. So I believe it has to be something with the Tab implementation.
One thing is that MvvmCross 3.1.1 not is build for iOS unified code. This will prevent you from submitting your app. MvvmCross 4.0 is currently in beta, but i would recommend using it, because it has many fixes.
If the code crashes on line 44 while trying to resolve IMvxViewModelLoader, it probably means that you are missing some package where the IMvxViewModelLoader is.
I'm getting a System.MissingMethodException when I try to instantiate a Dictionary using the Android.Gms.Maps.Model.Marker class as follows:
Dictionary<Marker, MyInnerClass> _markers = new Dictionary<Marker, MyInnerClass>();
I suspect that somehow a needed dll is not being loaded but don't know why. The problem seems to be specific to my specific dev environment since other developers with the same code are not seeing this problem. I can reproduce the issue in Genymotion, an Asus Tablet and a GS4 all running Android 4.2.2.
Application output reports the following:
[] Missing method Android.Runtime.JNIEnv::AllocObject(Type) in assembly Mono.Android.dll, referenced in assembly GooglePlayServices.dll
Here's the stack trace:
System.MissingMethodException: Method not found: 'Android.Runtime.JNIEnv.AllocObject'.
at MyProduct.Maps.MyMapFragment..ctor () [0x00013] in /Users/me/code/my.domain/MyProduct/Maps/MyMapFragment.cs:48
at at (wrapper dynamic-method) object.ffa689fb-fdde-4e08-abd8-3bdf6ae641fb (intptr,object[]) <IL 0x00018, 0x00037>
at Java.Interop.TypeManager.n_Activate (intptr,intptr,intptr,intptr,intptr,intptr) [0x00070] in /Users/builder/data/lanes/monodroid-mlion-monodroid-4.8.2-branch/a25a31d0/source/monodroid/src/Mono.Android/src/Java.Interop/TypeManager.cs:141
at at (wrapper native-to-managed) Java.Interop.TypeManager.n_Activate (intptr,intptr,intptr,intptr,intptr,intptr) <IL 0x00020, 0x0007f>
at at (wrapper managed-to-native) object.wrapper_native_0xb65e0e20 (intptr,intptr,intptr,intptr,Android.Runtime.JValue[]) <0x00003>
at Android.Runtime.JNIEnv.CallNonvirtualVoidMethod (intptr,intptr,intptr,Android.Runtime.JValue[]) [0x00000] in /Users/builder/data/lanes/monodroid-mlion-monodroid-4.8.2-branch/a25a31d0/source/monodroid/src/Mono.Android/src/Runtime/JNIEnv.g.cs:612
at Android.App.Activity.SetContentView (int) [0x00070] in /Users/builder/data/lanes/monodroid-mlion-monodroid-4.8.2-branch/a25a31d0/source/monodroid/src/Mono.Android/platforms/android-15/src/generated/Android.App.Activity.cs:3824
at MyProduct.MyListActivity.OnCreate (Android.OS.Bundle) [0x00079] in /Users/me/code/my.domain/MyProduct/MyListActivity.cs:83
at Android.App.Activity.n_OnCreate_Landroid_os_Bundle_ (intptr,intptr,intptr) [0x00011] in /Users/builder/data/lanes/monodroid-mlion-monodroid-4.8.2-branch/a25a31d0/source/monodroid/src/Mono.Android/platforms/android-15/src/generated/Android.App.Activity.cs:1937
at at (wrapper dynamic-method) object.24a01956-09ee-4dec-9155-eff468f7249c (intptr,intptr,intptr) <IL 0x00017, 0x0001f>
Android.Runtime.JNIEnv.AllocObject() is a method that was added to Xamarin.Android 4.10.1.
It would seem that GooglePlayServices.dll was built against 4.10, while your app was packaged against 4.8 (which doesn't contain AllocObject()). This would explain the MissingMethodException.
Xamarin.Android 4.10.1 is now stable; please upgrade.
How do I debug a mono project? I can't seem to run it. It builds perfectly. But running it is another issue altogether.
This is the output from running it.
$ mono SvnTest.exe update
Stacktrace:
at (wrapper managed-to-native) System.Runtime.InteropServices.Marshal.PtrToStringAnsi (intptr) <0x00045>
at (wrapper managed-to-native) System.Runtime.InteropServices.Marshal.PtrToStringAnsi (intptr) <0x00045>
at PumaCode.SvnDotNet.AprSharp.AprString.ToString () <0x0004b>
at PumaCode.SvnDotNet.SubversionSharp.SvnException.ExtractMessage (PumaCode.SvnDotNet.SubversionSharp.SvnError) <0x00033>
at PumaCode.SvnDotNet.SubversionSharp.SvnException..ctor (PumaCode.SvnDotNet.SubversionSharp.SvnError) <0x0001b>
at PumaCode.SvnDotNet.SubversionSharp.SvnClient.Update (PumaCode.SvnDotNet.SubversionSharp.SvnPath,PumaCode.SvnDotNet.SubversionSharp.SvnOptRevision,bool,PumaCode.SvnDotNet.SubversionSharp.SvnClientContext,PumaCode.SvnDotNet.AprSharp.AprPool) <0x000e3>
at PumaCode.SvnDotNet.SubversionSharp.SvnClient.Update (string,PumaCode.SvnDotNet.SubversionSharp.SvnRevision,bool) <0x0009f>
at PumaCode.SvnDotNet.SubversionSharp.SvnMockApp.UpdateCmd.Execute () <0x0015f>
at PumaCode.SvnDotNet.SubversionSharp.SvnMockApp.CmdBase.Run (PumaCode.SvnDotNet.SubversionSharp.SvnMockApp.Application/SubCommand,string[]) <0x00551>
at (wrapper runtime-invoke) <Module>.runtime_invoke_int__this___object_object (object,intptr,intptr,intptr) <0x00060>
at (wrapper managed-to-native) System.Reflection.MonoMethod.InternalInvoke (object,object[],System.Exception&) <0x00057>
at (wrapper managed-to-native) System.Reflection.MonoMethod.InternalInvoke (object,object[],System.Exception&) <0x00057>
at System.Reflection.MonoMethod.Invoke (object,System.Reflection.BindingFlags,System.Reflection.Binder,object[],System.Globalization.CultureInfo) <0x001ab>
at System.Reflection.MethodBase.Invoke (object,object[]) <0x0002d>
at PumaCode.SvnDotNet.SubversionSharp.SvnMockApp.Application.Run (string[]) <0x0034b>
at PumaCode.SvnDotNet.SubversionSharp.SvnMockApp.Application.Main (string[]) <0x00037>
at (wrapper runtime-invoke) <Module>.runtime_invoke_int_object (object,intptr,intptr,intptr) <0x00054>
Native stacktrace:
mono() [0x48419c]
mono() [0x4ce1bf]
/lib/libpthread.so.0(+0xee80) [0x7f64b72b2e80]
/lib/libc.so.6(strlen+0x12) [0x7f64b6d477c2]
mono(mono_string_new+0x1d) [0x57f80d]
[0x4047e705]
Debug info from gdb:
=================================================================
Got a SIGSEGV while executing native code. This usually indicates
a fatal error in the mono runtime or one of the native libraries
used by your application.
=================================================================
Aborted
toString() method
public override string ToString()
{
if(IsNull)
return ("[apr_string:NULL]");
else
return (Marshal.PtrToStringAnsi(mString));
}
Clearly the mString member contains a garbage pointer. Judging from the call stack, you'll need help from the SubversionSharp team. Or find out somehow why it is trying to handle a Subversion error.
The last post at their web site dates from 2006, "We're not dead!". Their forum server looks pretty dead to me though. Good luck.