How to read linker error in Xamarin - xamarin

I get the following error while executing my Xamarin Android app in release mode. I suppose something is missing in LinkerPleaseInclude.cs, but the error message is not very helpful.
09-25 16:17:38.140 W/art ( 1082): JNI RegisterNativeMethods: attempt to register 0 native methods for mvvmcross.binding.droid.views.MvxRadioGroup
[0:] MvxBind:Error: 2,89 Exception thrown during the view binding ArgumentNullException: missing source event info in MvxWeakEventSubscription
Parameter name: sourceEventInfo
at MvvmCross.Platform.WeakSubscription.MvxWeakEventSubscription`2[TSource,TEventArgs]..ctor (Android.Widget.TextView source, System.Reflection.EventInfo sourceEventInfo, System.EventHandler`1[TEventArgs] targetEventHandler) [0x00017] in <54d9eb77c4d448d4bc5e7c7a5cdd0a97>:0
at MvvmCross.Platform.WeakSubscription.MvxWeakEventSubscription`2[TSource,TEventArgs]..ctor (Android.Widget.TextView source, System.String sourceEventName, System.EventHandler`1[TEventArgs] targetEventHandler) [0x00012] in <54d9eb77c4d448d4bc5e7c7a5cdd0a97>:0
at MvvmCross.Platform.WeakSubscription.MvxWeakSubscriptionExtensionMethods.WeakSubscribe[TSource,TEventArgs] (TSource source, System.String eventName, System.EventHandler`1[TEventArgs] eventHandler) [0x00000] in <54d9eb77c4d448d4bc5e7c7a5cdd0a97>:0
at MvvmCross.Binding.Droid.Target.MvxTextViewTextTargetBinding.SubscribeToEvents () [0x0000b] in <cc9453c0f5794d529a8b1975bb62dd40>:0
at MvvmCross.Binding.Bindings.MvxFullBinding.CreateTargetBinding (System.Object target) [0x00057] in <5d9349f2d9c240e38eaeca40fe71d977>:0
at MvvmCross.Binding.Bindings.MvxFullBinding..ctor (MvvmCross.Binding.MvxBindingRequest bindingRequest) [0x0002f] in <5d9349f2d9c240e38eaeca40fe71d977>:0
at MvvmCross.Binding.Binders.MvxFromTextBinder.BindSingle (MvvmCross.Binding.MvxBindingRequest bindingRequest) [0x00000] in <5d9349f2d9c240e38eaeca40fe71d977>:0
at MvvmCross.Binding.Binders.MvxFromTextBinder+<>c__DisplayClass2_0.<Bind>b__0 (MvvmCross.Binding.Bindings.MvxBindingDescription description) [0x00018] in <5d9349f2d9c240e38eaeca40fe71d977>:0
at System.Linq.Utilities+<>c__DisplayClass2_0`3[TSource,TMiddle,TResult].<CombineSelectors>b__0 (TSource x) [0x00012] in <9ecdeee51aa740839577d6db9550e95f>:0
at System.Linq.Utilities+<>c__DisplayClass2_0`3[TSource,TMiddle,TResult].<CombineSelectors>b__0 (TSource x) [0x00000] in <9ecdeee51aa740839577d6db9550e95f>:0
at (wrapper delegate-invoke) System.Func`2[System.Collections.Generic.KeyValuePair`2[System.String,MvvmCross.Binding.Parse.Binding.MvxSerializableBindingDescription],System.Collections.Generic.KeyValuePair`2[System.Object,MvvmCross.Binding.Bindings.IMvxUpdateableBinding]]:invoke_TResult_T (System.Collections.Generic.KeyValuePair`2<string, MvvmCross.Binding.Parse.Binding.MvxSerializableBindingDescription>)
at System.Linq.Enumerable+SelectEnumerableIterator`2[TSource,TResult].MoveNext () [0x00048] in <9ecdeee51aa740839577d6db9550e95f>:0
at System.Collections.Generic.List`1[T].InsertRange (System.Int32 index, System.Collections.Generic.IEnumerable`1[T] collection) [0x000ea] in <b2855d13f99e445b95990a59348d98e8>:0
at System.Collections.Generic.List`1[T].AddRange (System.Collections.Generic.IEnumerable`1[T] collection) [0x00000] in <b2855d13f99e445b95990a59348d98e8>:0
at MvvmCross.Binding.Droid.Binders.MvxAndroidViewBinder.StoreBindings (Android.Views.View view, System.Collections.Generic.IEnumerable`1[T] newBindings) [0x00028] in <cc9453c0f5794d529a8b1975bb62dd40>:0
at MvvmCross.Binding.Droid.Binders.MvxAndroidViewBinder.ApplyBindingsFromAttribute (Android.Views.View view, Android.Content.Res.TypedArray typedArray, System.Int32 attributeId) [0x0001c] in <cc9453c0f5794d529a8b1975bb62dd40>:0
I see, something is missing with MvxRadioGroup. How do I find out what to add in LinkerPleaseInclude?
My binding for MvxRadioGroup is the following:
<MvxRadioGroup
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_marginTop="6dp"
local:MvxBind="ItemsSource GenderAnswers; SelectedItem GenderAnswer"
local:MvxItemTemplate="#layout/radioitem_enum" />
and my LinkerPleaseInclude is still empty.
Here's the defintiion of the properties in view model:
public IEnumerable<GenderQuestionAnswers> GenderAnswers => Enum.GetValues(typeof(GenderQuestionAnswers)).Cast<GenderQuestionAnswers>();
public GenderQuestionAnswers? GenderAnswer
{
get => _genderAnswer;
set => SetProperty(ref _genderAnswer, value);
}
[edit 2017-09-27]: added code for MvxRadioGroup binding
[edit 2017-09-27]: added snippet for properties in view model

I ended up adding theses lines to LinkerPleaseInclude in addition to the file mentioned by #york-shen-msft
public void Include(RadioButton radioButton)
{
radioButton.CheckedChange += (sender, args) => radioButton.Checked = args.IsChecked
}
Well, that doesn't really answer my question as I wanted to know how to find the correct solution without searching the whole internet for lines others included before and do trial and error, but it solves my actual problem for the moment.

Related

Can't resolve Prism DryIoc Forms IModuleCatalog

I am having a weird issue with the entry point of my app in App.xaml.cs when an interface is being resolved by Prism MVVM.
public App(IPlatformIniializer initializer) : base(initializer) {}
Stack Trace
The issue I am having does not stem from my code (at least I can't see so) so here is the stack trace as I do not know what to post, and I can't post my entire project here.
The error starts in CreateFormsApp() as the trace shows, the line is var app = new App(new AndroidInitializer());
And then from there, it goes into Prisms library code. I had a look at their source code and I can see it on like 150 of this.
When IModuleCatalog is being resolved it throws an error, I don't know how I can fix something like this.
Has anyone encountered this before?
at Prism.DryIoc.DryIocContainerExtension.Resolve (System.Type type, System.ValueTuple`2[System.Type,System.Object][] parameters) [0x00053] in /_/src/Containers/Prism.DryIoc.Shared/DryIocContainerExtension.cs:298
at Prism.DryIoc.DryIocContainerExtension.Resolve (System.Type type) [0x00000] in /_/src/Containers/Prism.DryIoc.Shared/DryIocContainerExtension.cs:272
at Prism.Ioc.IContainerProviderExtensions.Resolve[T] (Prism.Ioc.IContainerProvider provider) [0x00000] in /_/src/Prism.Core/Ioc/IContainerProviderExtensions.cs:18
at Prism.PrismApplicationBase.Initialize () [0x00057] in /_/src/Forms/Prism.Forms/PrismApplicationBase.cs:150
at Prism.PrismApplicationBase.InitializeInternal () [0x00006] in /_/src/Forms/Prism.Forms/PrismApplicationBase.cs:94
at Prism.PrismApplicationBase..ctor (Prism.IPlatformInitializer platformInitializer) [0x00031] in /_/src/Forms/Prism.Forms/PrismApplicationBase.cs:72
at Prism.DryIoc.PrismApplication..ctor (Prism.IPlatformInitializer platformInitializer) [0x00000] in /_/src/Forms/Prism.DryIoc.Forms/PrismApplication.cs:25
at MyApp.App..ctor (Prism.IPlatformInitializer initializer) [0x00000] in C:\Users\Steve\source\repos\MyApp\MyApp\App.xaml.cs:50
at MyApp.Droid.MainActivity.CreateFormsApp (Android.OS.Bundle bundle) [0x0021e] in C:\Users\Steve\source\repos\MyApp\MyApp.Android\MainActivity.cs:226

Xamarin.iOS UITest does not run with category

I have a lot of uitests for Xamarin.Forms app. These tests under categories. (For example LoginTest category has 10 tests, InboxTest category has 40 tests etc.) When I select 1 category (or when I select more than categories) and run it on iOS simulator, firstly tests of these categories runs, but after a while some tests don't run.
And I encounter this error:
Connection closed
Stack trace:
at MonoDevelop.Core.Execution.RemoteProcessConnection.SendMessage[RT] (MonoDevelop.Core.Execution.BinaryMessage`1[RT] message) [0x00024] in /Users/builder/azdo/_work/1/s/main/src/core/MonoDevelop.Core/MonoDevelop.Core.Execution/RemoteProcessConnection.cs:374
at MonoDevelop.UnitTesting.NUnit.External.ExternalTestRunner.Run (MonoDevelop.UnitTesting.NUnit.External.IRemoteEventListener listener, System.String[] nameFilter, System.String path, System.String suiteName, System.Collections.Generic.List`1[T] supportAssemblies, System.String testRunnerType, System.String testRunnerAssembly, System.String crashLogFile) [0x00099] in /Users/builder/azdo/_work/1/s/main/src/addins/MonoDevelop.UnitTesting.NUnit/MonoDevelop.UnitTesting.NUnit/ExternalTestRunner.cs:91
at Microsoft.VisualStudio.Threading.JoinableTask.CompleteOnCurrentThread () [0x001b6] in C:\A_work\107\s\src\Microsoft.VisualStudio.Threading\JoinableTask.cs:916
at Microsoft.VisualStudio.Threading.JoinableTask`1[T].CompleteOnCurrentThread () [0x00000] in C:\A_work\107\s\src\Microsoft.VisualStudio.Threading\JoinableTask`1.cs:84
at Microsoft.VisualStudio.Threading.JoinableTaskFactory.Run[T] (System.Func`1[TResult] asyncMethod, Microsoft.VisualStudio.Threading.JoinableTaskCreationOptions creationOptions) [0x0000e] in C:\A_work\107\s\src\Microsoft.VisualStudio.Threading\JoinableTaskFactory.cs:505
at Microsoft.VisualStudio.Threading.JoinableTaskFactory.Run[T] (System.Func`1[TResult] asyncMethod) [0x00000] in C:\A_work\107\s\src\Microsoft.VisualStudio.Threading\JoinableTaskFactory.cs:484
at MonoDevelop.UnitTesting.NUnit.NUnitAssemblyTestSuite.RunUnitTest (MonoDevelop.UnitTesting.UnitTest test, System.String suiteName, System.String pathName, System.String testName, MonoDevelop.UnitTesting.TestContext testContext) [0x00265] in /Users/builder/azdo/_work/1/s/main/src/addins/MonoDevelop.UnitTesting.NUnit/MonoDevelop.UnitTesting.NUnit/NUnitAssemblyTestSuite.cs:535
at MonoDevelop.UnitTesting.NUnit.NUnitTestSuite.OnRun (MonoDevelop.UnitTesting.TestContext testContext) [0x00000] in /Users/builder/azdo/_work/1/s/main/src/addins/MonoDevelop.UnitTesting.NUnit/MonoDevelop.UnitTesting.NUnit/NUnitTestSuite.cs:79
at MonoDevelop.UnitTesting.UnitTest.Run (MonoDevelop.UnitTesting.TestContext testContext) [0x0001c] in /Users/builder/azdo/_work/1/s/main/src/addins/MonoDevelop.UnitTesting/Services/UnitTest.cs:351
When I run it one by one, they run.
My Visual Studio mac version is 8.8.4 (up to date)
Xamarin.TestCloud.Agent version is 0.22.1
Xamarin.UITest version is 3.0.12
What must I do?
Thank you in advance.

Xamarin.Forms - MONO_GC_PARAMS=bridge-implementation=old - how to tell if it's working on Windows?

I'm seeing this cryptic exception that's been documented on bugzilla.xamarin.com periodically. Most of the posts suggest you can suppress the error by changing the bridge implementation to the Old version instead of Tarjan by setting an environment variable:
MONO_GC_PARAMS=bridge-implementation=old
I set the variable, but I don't see anything in my logcat or build output to indicate it's using one bridge or the other, and I'm still getting the exception. Is there a way to tell which implementation is being used?
Here's the stack trace - any suggestions are greatly appreciated.
Process: com.icon.iconsurvey, PID: 11543
android.runtime.JavaProxyThrowable: System.ArgumentException: Handle must be valid.
Parameter name: instance
at Java.Interop.JniEnvironment+InstanceMethods.CallNonvirtualVoidMethod (Java.Interop.JniObjectReference instance, Java.Interop.JniObjectReference type, Java.Interop.JniMethodInfo method, Java.Interop.JniArgumentValue* args) [0x00009] in <7cfbebb561c54efc9010b018c0846c7e>:0
at Android.Runtime.JNIEnv.CallNonvirtualVoidMethod (System.IntPtr jobject, System.IntPtr jclass, System.IntPtr jmethod, Android.Runtime.JValue* parms) [0x00015] in <e975227ac8644a30bb0866117325de0d>:0
at Android.Support.V4.Widget.DrawerLayout.RemoveDrawerListener (Android.Support.V4.Widget.DrawerLayout+IDrawerListener listener) [0x00088] in <fc4222de5c684a9abf7cc4821baac4cd>:0
at Xamarin.Forms.Platform.Android.AppCompat.NavigationPageRenderer.Dispose (System.Boolean disposing) [0x000e4] in <b5b1173f4d49442b898c45e26ae39e48>:0
at Java.Lang.Object.Dispose () [0x00000] in <e975227ac8644a30bb0866117325de0d>:0
at Xamarin.Forms.Platform.Android.AppCompat.Platform+<>c__DisplayClass35_0.<SetPage>b__0 () [0x00015] in <b5b1173f4d49442b898c45e26ae39e48>:0
at Java.Lang.Thread+RunnableImplementor.Run () [0x00008] in <e975227ac8644a30bb0866117325de0d>:0
at Java.Lang.IRunnableInvoker.n_Run (System.IntPtr jnienv, System.IntPtr native__this) [0x00008] in <e975227ac8644a30bb0866117325de0d>:0
at (wrapper dynamic-method) System.Object:1d7dae73-d3c1-4d29-aa82-708ecaa93ad1 (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:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:145)
at android.app.ActivityThread.main(ActivityThread.java:6939)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1404)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1199)
The current suggestion is using new rather than old when changing the default GC Bridge away from tarjan. You may have been told to use the "old" default which was technically new before changing to tarjan in Mono 4.6:
http://www.mono-project.com/docs/about-mono/releases/4.6.0/#new-default-gc-bridge-processor-on-android
You can see if this is being picked up by checking the Diagnostic Build Output of your project.
https://developer.xamarin.com/guides/android/troubleshooting/troubleshooting/#Diagnostic_MSBuild_Output
You would then look to ensure the configuration file is picked up with the respective arguments.

Link all in Xamarin release,failed with Autofac Assembly

When setting the Linker behaviour to "Link all" I get the following error at runtime:
Autofac.Core.DependencyResolutionException.
I've tried adding ignore assembly Autofac but without success.
Setting the Linker behavior to "Link Framework SDKs only" does work but I want to enable "Link All" if possible.
Thanks in advance.
Update :
ReflectionActivator.ActivateInstance (Autofac.IComponentContext context, System.Collections.Generic.IEnumerable`1[T] parameters)
Autofac.Core.DependencyResolutionException: No constructors on type 'Eela.Taxi.Service.RestService' can be found with the constructor finder 'Autofac.Core.Activators.Reflection.DefaultConstructorFinder'.
No constructors on type 'Eela.Taxi.Service.RestService' can be found with the constructor finder 'Autofac.Core.Activators.Reflection.DefaultConstructorFinder'.
An error occurred during the activation of a particular registration. See the inner exception for details. Registration: Activator = RestService (ReflectionActivator), Services = [Eela.Model.Xamarin.Interfaces.IRestService], Lifetime = Autofac.Core.Lifetime.CurrentScopeLifetime, Sharing = None, Ownership = OwnedByLifetimeScope ---> No constructors on type 'Eela.Taxi.Service.RestService' can be found with the constructor finder 'Autofac.Core.Activators.Reflection.DefaultConstructorFinder'. (See inner exception for details.)
1
ReflectionActivator.ActivateInstance (Autofac.IComponentContext context, System.Collections.Generic.IEnumerable`1[T] parameters)
2
InstanceLookup.Activate (System.Collections.Generic.IEnumerable`1[T] parameters)
An error occurred during the activation of a particular registration. See the inner exception for details. Registration: Activator = RestService (ReflectionActivator), Services = [Eela.Model.Xamarin.Interfaces.IRestService], Lifetime = Autofac.Core.Lifetime.CurrentScopeLifetime, Sharing = None, Ownership = OwnedByLifetimeScope ---> No constructors on type 'Eela.Taxi.Service.RestService' can be found with the constructor finder 'Autofac.Core.Activators.Reflection.DefaultConstructorFinder'. (See inner exception for details.)
1
InstanceLookup.Activate (System.Collections.Generic.IEnumerable`1[T] parameters)
2
InstanceLookup.Execute ()
3
ResolveOperation.GetOrCreateInstance (Autofac.Core.ISharingLifetimeScope currentOperationScope, Autofac.Core.IComponentRegistration registration, System.Collections.Generic.IEnumerable`1[T] parameters)
4
ResolveOperation.ResolveComponent (Autofac.Core.IComponentRegistration registration, System.Collections.Generic.IEnumerable`1[T] parameters)
5
ResolveOperation.Execute (Autofac.Core.IComponentRegistration registration, System.Collections.Generic.IEnumerable`1[T] parameters)
6
LifetimeScope.ResolveComponent (Autofac.Core.IComponentRegistration registration, System.Collections.Generic.IEnumerable`1[T] parameters)
7
Container.ResolveComponent (Autofac.Core.IComponentRegistration registration, System.Collections.Generic.IEnumerable`1[T] parameters)
8
ResolutionExtensions.TryResolveService (Autofac.IComponentContext context, Autofac.Core.Service service, System.Collections.Generic.IEnumerable`1[T] parameters, System.Object& instance)
9
ResolutionExtensions.ResolveService (Autofac.IComponentContext context, Autofac.Core.Service service, System.Collections.Generic.IEnumerable`1[T] parameters)
10
ResolutionExtensions.Resolve (Autofac.IComponentContext context, System.Type serviceType, System.Collections.Generic.IEnumerable`1[T] parameters)
11
ResolutionExtensions.Resolve[TService] (Autofac.IComponentContext context, System.Collections.Generic.IEnumerable`1[T] parameters)
12
ResolutionExtensions.Resolve[TService] (Autofac.IComponentContext context)
13
App+<OnStart>d__4.MoveNext ()
14
ExceptionDispatchInfo.Throw ()
15
AsyncMethodBuilderCore+<>c.<ThrowAsync>b__6_0 (System.Object state)
16
SyncContext+<>c__DisplayClass2_0.<Post>b__0 ()
17
Thread+RunnableImplementor.Run ()
18
IRunnableInvoker.n_Run (System.IntPtr jnienv, System.IntPtr native__this)
19
(wrapper dynamic-method) System.Object:f9684b08-49ee-4f47-8b7c-c59b675c18f3 (intptr,intptr)
So as your Stack Trace indicates. Autofac is trying to instantiate an instance of Eela.Taxi.Service.RestService. However, it seems like the Mono Linker has removed the constructor because it is never directly invoked.
So you could do a couple of things. You could:
Add your assembly to be ignored from the linker
You could add a [Preserve] attribute on your RestService to tell the Linker not to touch it
You could similar to what MvvmCross does have a LinkerPleaseInclude.cs file which describes usage of each type that get stripped out. So for every one you discover you will need to add it here.
So 1. and 2. are fairly self explanatory. You have already used 1. for autofac, just do the same for your own assembly containing RestService. However, the downside here is that nothing in this assembly will be linked, potentially leaving you with a lot more code in it than actually needed.
For 2. you simply add [Preserve] right before declaring your class. So something like:
[Preserve]
public class RestService : IRestService { }
You may also consider using it with AllMembers = true: [Preserve(AllMembers = true)] to keep member fields too.
As for the last option. You basically create a LinkerPleaseInclude.cs in your App project. You let the linker do its job. You continue adding stuff to the class until the Linker does kill your App at runtime. So a start on LinkerPleaseInclude.cs could look like:
[Preserve(AllMembers = true)]
public class LinkerPleaseInclude
{
public void Include(IRestService service)
{
service = new RestService();
}
}
This class is never invoked, but it is enough for the linker to know that the constructor of RestService should not be linked out.

parse.com query throws stack overflow exception under mono

I am building a simple C# mono application that queries data from parse.com server.
Nothing special:
private static async Task<ParseGameData> DownloadGameData(DateTime dateFrom)
{
ParseGameData gameData = new ParseGameData();
InitParse();
var qHits = ParseObject.GetQuery("Hits").WhereGreaterThan("createdAt", dateFrom)
.Limit(100).OrderBy("createdAt");
gameData.hits = await qHits.FindAsync();
return gameData;
}
And called from another function:
ParseGameData gameData = DownloadGameData(timestamp).Result;
This works great and no exception is being thrown when querying small amount (~less than 75 records). But if I set the limit higher, application crashes and I get this:
Unhandled Exception:
System.StackOverflowException: The requested operation caused a stack overflow.
at System.Threading.Tasks.Task.FinishContinuations () [0x00000] in <filename unknown>:0
at System.Threading.Tasks.Task.FinishStageThree () [0x00000] in <filename unknown>:0
at System.Threading.Tasks.Task`1[System.Threading.Tasks.TaskExtensions+VoidResult].TrySetResult (VoidResult result) [0x00000] in <filename unknown>:0
at System.Threading.Tasks.UnwrapPromise`1[System.Threading.Tasks.TaskExtensions+VoidResult].TrySetFromTask (System.Threading.Tasks.Task task, Boolean lookForOce) [0x00000] in <filename unknown>:0
at System.Threading.Tasks.UnwrapPromise`1[System.Threading.Tasks.TaskExtensions+VoidResult].InvokeCore (System.Threading.Tasks.Task completingTask) [0x00000] in <filename unknown>:0
at System.Threading.Tasks.UnwrapPromise`1[System.Threading.Tasks.TaskExtensions+VoidResult].Invoke (System.Threading.Tasks.Task completingTask) [0x00000] in <filename unknown>:0
... and then these lines repeat.
For interest purposes: each record in database takes about ~65KB, so a 100 hits would be 6.5MB.
I've tried this code on two mono platforms, on OS X and Linux. Both platforms throw stackoverflow exceptions. However on Windows, using .NET, it works fine, even with 1000 limit. That leads me to believe it is something with mono and parse.com libraries. Any suggestions?
It seems like it was a parse library bug. I have downgraded parse lib from 1.5.5 to 1.5.4 and now it works fine.

Resources