Xamarin Studio 6 F# Android Unit Test App NotFoundException - xamarin

I am using Xamarin Studio Community Version 6 on a Mac.
Create a new "Android/Tests/Unit Test App/F#" project.
Run in an emulator.
"Android/Tests/Unit Test App/C#" projects work fine.
Here is the exception detail:
Android.Content.Res.Resources+NotFoundException: Resource ID #0x7f020003
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in /Users/builder/data/lanes/2923/52635947/source/mono/external/referencesource/mscorlib/system/runtime/exceptionservices/exceptionservicescommon.cs:143
at Java.Interop.JniEnvironment+InstanceMethods.CallNonvirtualVoidMethod (JniObjectReference instance, JniObjectReference type, Java.Interop.JniMethodInfo method, Java.Interop.JniArgumentValue* args) [0x000a7] in /Users/builder/data/lanes/2923/52635947/source/Java.Interop/src/Java.Interop/Java.Interop/JniEnvironment.g.cs:12083
at Java.Interop.JniPeerMembers+JniInstanceMethods.InvokeVirtualVoidMethod (System.String encodedMember, IJavaPeerable self, Java.Interop.JniArgumentValue* parameters) [0x00068] in /Users/builder/data/lanes/2923/52635947/source/Java.Interop/src/Java.Interop/Java.Interop/JniPeerMembers.JniInstanceMethods_Invoke.cs:31
at Android.App.Activity.SetContentView (Int32 layoutResID) [0x00017] in /Users/builder/data/lanes/2923/52635947/source/monodroid/src/Mono.Android/platforms/android-19/src/generated/Android.App.Activity.cs:4102
at Xamarin.Android.NUnitLite.TestSuiteActivity.OnCreate (Android.OS.Bundle bundle) [0x0001b] in /Users/builder/data/lanes/2923/52635947/source/monodroid/src/NUnit/Gui/Activities/TestSuiteActivity.cs:39
at XamarinTemplate.Core.Tests.FSharp.MainActivity.OnCreate (Android.OS.Bundle bundle) [0x0000c] in /Users/don/dev/15x10/XamarinTemplate/XamarinTemplate.Core.Tests.FSharp/MainActivity.fs:17
at Android.App.Activity.n_OnCreate_Landroid_os_Bundle_ (IntPtr jnienv, IntPtr native__this, IntPtr native_savedInstanceState) [0x00011] in /Users/builder/data/lanes/2923/52635947/source/monodroid/src/Mono.Android/platforms/android-19/src/generated/Android.App.Activity.cs:2102
at at (wrapper dynamic-method) System.Object:11410e9c-5bf3-4341-b40b-0fd0770022bf (intptr,intptr,intptr)
at --- End of managed exception stack trace ---
at android.content.res.Resources$NotFoundException: Resource ID #0x7f020003
at at android.content.res.Resources.getValue(Resources.java:1266)
at at android.content.res.Resources.loadXmlResourceParser(Resources.java:2649)
at at android.content.res.Resources.getLayout(Resources.java:1082)
at at android.view.LayoutInflater.inflate(LayoutInflater.java:412)
at at android.view.LayoutInflater.inflate(LayoutInflater.java:365)
at at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:378)
at at android.app.Activity.setContentView(Activity.java:2145)
at at md5cb9b4e367aed809f464e8979fc58f264.MainActivity.n_onCreate(Native Method)
at at md5cb9b4e367aed809f464e8979fc58f264.MainActivity.onCreate(MainActivity.java:29)
at at android.app.Activity.performCreate(Activity.java:5990)
at at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106)
at at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2278)
at at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387)
at at android.app.ActivityThread.access$800(ActivityThread.java:151)
at at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)
at at android.os.Handler.dispatchMessage(Handler.java:102)
at at android.os.Looper.loop(Looper.java:135)
at at android.app.ActivityThread.main(ActivityThread.java:5254)
at at java.lang.reflect.Method.invoke(Native Method)
at at java.lang.reflect.Method.invoke(Method.java:372)
at at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
at at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)

A bit late, however, this is now fixed. Update to the latest version of Xamarin. Be sure to delete your existing project, and create a new one. The templates have been updated.
This was a bug in how unit test project was set up (A Resource type-provider has since been implemented) and correctly handles the resource IDs. https://github.com/xamarin/xamarin-android/issues/1513

Related

My Xamarin.Android app can't be started anymore via intent

A few months ago my app was working fine when it gets started by an intent from another app.
Now when my app gets started via intent I get the error:
03-21 12:00:43.096 Google Pixel 3 XL Info 1234 ActivityManager Showing crash dialog for package com.comp.myapp u0
03-21 12:00:43.085 Google Pixel 3 XL Error 5860 AndroidRuntime --- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.AsyncMethodBuilderCore+<>c.<ThrowAsync>b__6_0 (System.Object state) [0x00000] in <c282b05120ba4b698b1a1e9d68af4131>:0
at Android.App.SyncContext+<>c__DisplayClass2_0.<Post>b__0 () [0x00000] in <e2a51596e3434d12a5bd106b9a0f0644>:0
at Java.Lang.Thread+RunnableImplementor.Run () [0x00008] in <e2a51596e3434d12a5bd106b9a0f0644>:0
at Java.Lang.IRunnableInvoker.n_Run (System.IntPtr jnienv, System.IntPtr native__this) [0x00009] in <e2a51596e3434d12a5bd106b9a0f0644>:0
at (wrapper dynamic-method) System.Object.6(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:193)
at android.app.ActivityThread.main(ActivityThread.java:6718)
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:858)
Force finishing activity com.comp.myapp/md5ac266b5641403f314bbc23831457c9e5.MainActivity
This crash seems to happen before my app runs the OnCreate() method as I don't find what I log via Log.Debug() in LogCat.
My app works without problems, when I start it directly. In that state it also has no problems taking intents from other apps and processing them appropriately.
It turned out that my OnCreate method wasn't started because it was:
async public override void OnCreate(Bundle savedInstanceState, PersistableBundle persistentState)
{
instead of
async protected override void OnCreate(Bundle savedInstanceState)
{

Xamarin Android crashing with Xamarin.Auth

I'm using Xamarin.Auth to log into Facebook. I created a separate Renderer for iOS and Android.
In the auth.Completed I call a method AfterLogin(UserInfo) in the PCL class of the custom renderer. This does some additional work and then calls
App.Current.MainPage = new NavigationPage(new MainPage());
It looks like the page is constructed correctly and all methods return correctly until an Exception Unhandled gets thrown. The only text is "An unhandled exception occured."
In iOS, everything works fine. It calls the exact same PCL code.
I have no idea what view it is referring to.
Edit
Stack trace from ADB
I/MonoDroid(11638): UNHANDLED EXCEPTION:
I/MonoDroid(11638): Java.Lang.IllegalArgumentException: No view found for id 0x4 (unknown) for fragment FragmentContainer{436fa3e8 #0 id=0x4}
I/MonoDroid(11638): at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in <d18287e1d683419a8ec3216fd78947b9>:0
I/MonoDroid(11638): at Java.Interop.JniEnvironment+InstanceMethods.CallBooleanMethod (Java.Interop.JniObjectReference instance, Java.Interop.JniMethodInfo method) [0x00068] in <5716a943049b49ca928a3a1c8d2386f4>:0
I/MonoDroid(11638): at Android.Runtime.JNIEnv.CallBooleanMethod (System.IntPtr jobject, System.IntPtr jmethod) [0x0000e] in <33e6e739ac344166b157e323586f11a1>:0
I/MonoDroid(11638): at Android.Support.V4.App.FragmentManagerInvoker.ExecutePendingTransactions () [0x00033] in <7e083afc7c9045f59e01d9c14931060d>:0
I/MonoDroid(11638): at Xamarin.Forms.Platform.Android.AppCompat.NavigationPageRenderer.Dispose (System.Boolean disposing) [0x00083] in C:\BuildAgent3\work\ca3766cfc22354a1\Xamarin.Forms.Platform.Android\AppCompat\NavigationPageRenderer.cs:135
I/MonoDroid(11638): at Java.Lang.Object.Dispose () [0x00000] in <33e6e739ac344166b157e323586f11a1>:0
I/MonoDroid(11638): at Xamarin.Forms.Platform.Android.AppCompat.Platform.SetPage (Xamarin.Forms.Page newRoot) [0x0003f] in C:\BuildAgent3\work\ca3766cfc22354a1\Xamarin.Forms.Platform.Android\AppCompat\Platform.cs:226
I/MonoDroid(11638): at Xamarin.Forms.Platform.Android.FormsAppCompatActivity.InternalSetPage (Xamarin.Forms.Page page) [0x0001a] in C:\BuildAgent3\work\ca3766cfc22354a1\Xamarin.Forms.Platform.Android\AppCompat\FormsAppCompatActivity.cs:370
I/MonoDroid(11638): at Xamarin.Forms.Platform.Android.FormsAppCompatActivity.AppOnPropertyChanged (System.Object sender, System.ComponentModel.PropertyChangedEventArgs args) [0x00012] in C:\BuildAgent3\work\ca3766cfc22354a1\Xamarin.Forms.Platform.Android\AppCompat\FormsAppCompatActivity.cs:321
I/MonoDroid(11638): at Xamarin.Forms.BindableObject.OnPropertyChanged (System.String propertyName) [0x0000a] in C:\BuildAgent3\work\ca3766cfc22354a1\Xamarin.Forms.Core\BindableObject.cs:136
I/MonoDroid(11638): at Xamarin.Forms.Element.OnPropertyChanged (System.String propertyName) [0x00000] in C:\BuildAgent3\work\ca3766cfc22354a1\Xamarin.Forms.Core\Element.cs:380
I/MonoDroid(11638): at Xamarin.Forms.Application.set_MainPage (Xamarin.Forms.Page value) [0x0008b] in C:\BuildAgent3\work\ca3766cfc22354a1\Xamarin.Forms.Core\Application.cs:90
I/MonoDroid(11638): at App.App.Instance_DataIsReady (System.Object sender, App.EventArguments.DataIsReadyEventArgs e) [0x0004d] in <9b95d86146df403c82b64e5a8ab6a9cf>:0
I/MonoDroid(11638): at (wrapper delegate-invoke) <Module>:invoke_void_object_DataIsReadyEventArgs (object,App.EventArguments.DataIsReadyEventArgs)
I/MonoDroid(11638): at App.DataCache.OnDataIsReady (App.EventArguments.DataIsReadyStates state) [0x0001b] in <9b95d86146df403c82b64e5a8ab6a9cf>:0
I/MonoDroid(11638): at App.DataCache.set_PlayerWinnings (System.Collections.Generic.IEnumerable`1[T] value) [0x00012] in <9b95d86146df403c82b64e5a8ab6a9cf>:0
I/MonoDroid(11638): at App.DataCache+<RefreshData>d__37.MoveNext () [0x00351] in <9b95d86146df403c82b64e5a8ab6a9cf>:0
I/MonoDroid(11638): --- End of stack trace from previous location where exception was thrown ---
Which version of Xamarin.Auth?
Why implementing Xamarin.Forms support if it is already in the library itself since version 1.5.0?
And for more help we'll need more info from your side (and your code)...
The issue turned out to be that MainPage was being assigned to twice. It wasn't related to Auth.

MvvmCross ExoPlayer Sample causes "System.TypeLoadException: Type '__callback_factory__class__' is not finished"

I am trying to use the ExoPlayerXamarin sample but have been running into several issues. The first issue being that the sample had insufficient project settings and resources (i.e. no Android manifest). The next problem was that the Activity attribute was missing "MainLauncher = true".
Now I am running into another problem. When debugging the sample, during initialization I get:
System.Reflection.ReflectionTypeLoadException: The classes in the module cannot be loaded.
Full stack trace below. The class in question is __class_factory__ and is a dynamic class. The exception is caused because MvvmCross initialization in FindSetupType is looking for a specific type in the assembly but this dynamic assembly is not yet ready and causes a crash.
I just want to use the sample... does anybody know how I can work around this?
Thanks
System.TypeLoadException: Type '__callback_factory__class__' is not finished
System.Reflection.ReflectionTypeLoadException: The classes in the module cannot be loaded.
at System.Reflection.Emit.AssemblyBuilder.GetTypes (System.Boolean exportedOnly) [0x00145] in /Users/builder/data/lanes/3819/c1d1c79c/source/mono/mcs/class/corlib/System.Reflection.Emit/AssemblyBuilder.cs:756
at System.Reflection.Assembly.GetTypes () [0x00000] in /Users/builder/data/lanes/3819/c1d1c79c/source/mono/mcs/class/corlib/System.Reflection/Assembly.cs:405
at System.Reflection.Assembly+<>c__Iterator0.MoveNext () [0x00021] in /Users/builder/data/lanes/3819/c1d1c79c/source/mono/mcs/class/corlib/System.Reflection/Assembly.cs:999
at MvvmCross.Platform.ReflectionExtensions+<GetTypes>d__0.MoveNext () [0x00064] in D:\git\MvvmCross\MvvmCross\Platform\Platform\ReflectionExtensions.cs:12
at System.Linq.Enumerable+<SelectManyIterator>c__Iterator5`3[TSource,TCollection,TResult].MoveNext () [0x0009a] in /Users/builder/data/lanes/3819/c1d1c79c/source/mono/mcs/class/referencesource/System.Core/System/Linq/Enumerable.cs:472
at System.Linq.Enumerable+WhereSelectEnumerableIterator`2[TSource,TResult].MoveNext () [0x00078] in /Users/builder/data/lanes/3819/c1d1c79c/source/mono/mcs/class/referencesource/System.Core/System/Linq/Enumerable.cs:282
at System.Linq.Enumerable.FirstOrDefault[TSource] (System.Collections.Generic.IEnumerable`1[T] source) [0x0003e] in /Users/builder/data/lanes/3819/c1d1c79c/source/mono/mcs/class/referencesource/System.Core/System/Linq/Enumerable.cs:976
at MvvmCross.Droid.Platform.MvxAndroidSetupSingleton.FindSetupType () [0x000b9] in <c9cff602f1404a9da5c69389736fa297>:0
at MvvmCross.Droid.Platform.MvxAndroidSetupSingleton.CreateSetup (Android.Content.Context applicationContext) [0x00000] in <c9cff602f1404a9da5c69389736fa297>:0
at MvvmCross.Droid.Platform.MvxAndroidSetupSingleton.EnsureSingletonAvailable (Android.Content.Context applicationContext) [0x00031] in <c9cff602f1404a9da5c69389736fa297>:0
at MvvmCross.Droid.Views.MvxActivityViewExtensions.EnsureSetupInitialized (MvvmCross.Droid.Views.IMvxAndroidView androidView) [0x00014] in <c9cff602f1404a9da5c69389736fa297>:0
at MvvmCross.Droid.Views.MvxActivityViewExtensions.OnViewCreate (MvvmCross.Droid.Views.IMvxAndroidView androidView, Android.OS.Bundle bundle) [0x0000d] in <c9cff602f1404a9da5c69389736fa297>:0
at MvvmCross.Droid.Views.MvxActivityAdapter.EventSourceOnCreateCalled (System.Object sender, MvvmCross.Platform.Core.MvxValueEventArgs`1[T] eventArgs) [0x0000c] in <c9cff602f1404a9da5c69389736fa297>:0
at (wrapper delegate-invoke) System.EventHandler`1[MvvmCross.Platform.Core.MvxValueEventArgs`1[Android.OS.Bundle]]:invoke_void_object_TEventArgs (object,MvvmCross.Platform.Core.MvxValueEventArgs`1<Android.OS.Bundle>)
at MvvmCross.Platform.Core.MvxDelegateExtensionMethods.Raise[T] (System.EventHandler`1[TEventArgs] eventHandler, System.Object sender, T value) [0x00000] in D:\git\MvvmCross\MvvmCross\Platform\Platform\Core\MvxDelegateExtensionMethods.cs:21
at MvvmCross.Platform.Droid.Views.MvxEventSourceActivity.OnCreate (Android.OS.Bundle bundle) [0x00014] in <927906a0a3f249d6bfc8757c0c8bdde7>:0
at MvvmCross.ExoPlayer.Droid.MvxVideoPlayerActivity`1[TViewModel].OnCreate (Android.OS.Bundle savedInstanceState) [0x00002] in C:\Users\agendum\Documents\Visual Studio 2015\Projects\MvvmCross\ExoPlayer.Droid\MvxVideoPlayerActivity.cs:145

TypeLoadException in Xamarin.Forms project without TypeName

I'm working on a simple ProjectOxford Face and Emotion APIs demo with Xamarin.Forms
I added the Face and Emotion APIs from Nuget to the PCL Forms project and all platform-specific projects I get a TypeLoadException but the TypeName property is empty, so I don't know what's not loading.
The "Link Behavior" setting in the iOS project is "Don't Link" and the app runs in the simulator, selects a picture but when it hits the method that is supposed to send it to Face and Emotion APIs I get the exception below.
System.TypeLoadException: Failure has occurred while loading a type.
at System.Runtime.CompilerServices.AsyncTaskMethodBuilder.Start[TStateMachine] (TStateMachine& stateMachine) [0x00031] in /Library/Frameworks/Xamarin.iOS.framework/Versions/9.9.0.719/src/mono/external/referencesource/mscorlib/system/runtime/compilerservices/AsyncMethodBuilder.cs:316
at HelloForms.FaceViewModel.DoAnalyzePhoto () [0x0000f] in <filename unknown>:0
at HelloForms.FaceViewModel+<FaceViewModel>c__async8.MoveNext () [0x00021] in .../HelloForms/XPlat/HelloForms/ViewModels/FaceViewModel.cs:115
at --- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in /Library/Frameworks/Xamarin.iOS.framework/Versions/9.9.0.719/src/mono/external/referencesource/mscorlib/system/runtime/exceptionservices/exceptionservicescommon.cs:143
at System.Runtime.CompilerServices.AsyncMethodBuilderCore.<ThrowAsync>m__0 (System.Object state) [0x00000] in /Library/Frameworks/Xamarin.iOS.framework/Versions/9.9.0.719/src/mono/external/referencesource/mscorlib/system/runtime/compilerservices/AsyncMethodBuilder.cs:1018
at UIKit.UIKitSynchronizationContext+<Post>c__AnonStorey0.<>m__0 () [0x00000] in /Users/builder/data/lanes/1381/3afb4af5/source/maccore/src/UIKit/UIKitSynchronizationContext.cs:24
at Foundation.NSAsyncActionDispatcher.Apply () [0x00000] in /Users/builder/data/lanes/1381/3afb4af5/source/maccore/src/Foundation/NSAction.cs:163
at at (wrapper managed-to-native) UIKit.UIApplication:UIApplicationMain (int,string[],intptr,intptr)
at UIKit.UIApplication.Main (System.String[] args, System.IntPtr principal, System.IntPtr delegate) [0x00005] in /Users/builder/data/lanes/1381/3afb4af5/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/1381/3afb4af5/source/maccore/src/UIKit/UIApplication.cs:63
at HelloForms.iOS.Application.Main (System.String[] args) [0x00008] in .../HelloForms/XPlat/iOS/Main.cs:17

MvvmCross crashes on app start with "Method 'Array.Empty' not found" exception

I have recently updated my Xamarin.Android app MvvmCross package from 4.1.4 to 4.1.5 and now unable to launch my app. Couldn't even debug the issue as long as my code doesn't get any control before the crash.
System.MissingMethodException: Method 'Array.Empty' not found.
at MvvmCross.Droid.Views.MvxActivityViewExtensions.OnViewCreate (IMvxAndroidView androidView, Android.OS.Bundle bundle) [0x00055] in <filename unknown>:0
at MvvmCross.Droid.Views.MvxActivityAdapter.EventSourceOnCreateCalled (System.Object sender, MvvmCross.Platform.Core.MvxValueEventArgs`1 eventArgs) [0x0000c] in <filename unknown>:0
at at (wrapper delegate-invoke) System.EventHandler`1[MvvmCross.Platform.Core.MvxValueEventArgs`1[Android.OS.Bundle]]:invoke_void_object_TEventArgs (object,MvvmCross.Platform.Core.MvxValueEventArgs`1<Android.OS.Bundle>)
at MvvmCross.Platform.Core.MvxDelegateExtensionMethods.Raise[T] (System.EventHandler`1 eventHandler, System.Object sender, MvvmCross.Platform.Core.T value) [0x00000] in C:\vcs\git\MvvmCross\MvvmCross\Platform\Platform\Core\MvxDelegateExtensionMethods.cs:21
at MvvmCross.Platform.Droid.Views.MvxEventSourceActivity.OnCreate (Android.OS.Bundle bundle) [0x00014] in <filename unknown>:0
at MvvmCross.Droid.Views.MvxSplashScreenActivity.OnCreate (Android.OS.Bundle bundle) [0x00017] in <filename unknown>:0
at Android.App.Activity.n_OnCreate_Landroid_os_Bundle_ (IntPtr jnienv, IntPtr native__this, IntPtr native_savedInstanceState) [0x00011] in /Users/builder/data/lanes/3236/ee215fc9/source/monodroid/src/Mono.Android/platforms/android-23/src/generated/Android.App.Activity.cs:2857
at at (wrapper dynamic-method) System.Object:97318edf-ae39-4dd0-a17c-810218756b0b (intptr,intptr,intptr)
clean / rebuild doesn't help
rollback to 4.1.4 restores the app
This seems to be a current issue with MVVMCross and Mono. More information about it here: https://github.com/MvvmCross/MvvmCross/issues/1330

Resources