Xamarin.Auth Android Native UI not working - c#

I am using Xamarin.Auth to authenticate to my identity provider with implicit flow on Android. I can't get the native ui (chrome custom tabs) to work with Xamarin.Auth as I get the following error:
UNHANDLED EXCEPTION: 06-30 11:40:48.903 I/MonoDroid( 7670):
System.MissingMethodException: Method
'Android.Support.CustomTabs.CustomTabsIntent.LaunchUrl' not found.
06-30 11:40:48.903 I/MonoDroid( 7670): at
Android.App.Activity.n_OnCreate_Landroid_os_Bundle_ (System.IntPtr
jnienv, System.IntPtr native__this, System.IntPtr
native_savedInstanceState) [0x0000f] in
<93e2413825534efca8b597098003b511>:0 06-30 11:40:48.903 I/MonoDroid(
7670): at (wrapper dynamic-method)
System.Object:ce197f13-7701-4b2e-840f-19029a77ef6c
(intptr,intptr,intptr) 06-30 11:40:48.913 W/art ( 7670): JNI
RegisterNativeMethods: attempt to register 0 native methods for
android.runtime.JavaProxyThrowable 06-30 11:40:48.918 D/HockeyApp(
7670): Writing unhandled exception to:
/data/user/0/com.mycompany.myapp/files/9a7dae18-3c5a-4e97-b7cb-4a3f1581c690.stacktrace
My authenticator is set up like this:
var authenticator = new OAuth2Authenticator(
AuthSettings.ClientId,
AuthSettings.Scope,
new Uri(AuthSettings.AuthorizeUrl),
new Uri(AuthSettings.RedirectUrl),
null,
true);
I am not using linking either.
Any ideas?

After a quick google search I came accross an issue thread on a github page for the 'SharePlugin' for Xamarin, fortunately James Montemagno is in their helping out. The issue listed is similar to yours so for reference purposes it can be found Here.
It appears to have been a fairly common issue with this method 'Android.Support.CustomTabs.CustomTabsIntent::LaunchUrl'. In that thread they obviously mention that:
Release Mode => Linker option => None , Every thing works.
So that's worth double checking, to make sure that's what you're doing. (I realise you've mentioned you've had a look at the linked assemblies, but always worth a double check).
There is also some conversation on the GitHub repository for Xamarin.Auth iteself, a particular issue found Here talks about the versions of both Xamarin Auth and Xamarin Forms, needing to match in a certain way, I would suggest updating xamarin.forms to it's latest version, and trying again, perhaps even downgrading Xamarin.Auth.
It worked with 1.5.0-alpha-03. Tried with 1.5.0-alpha-09 but it
failed.

Related

iOS native library Xamarin binding

The problem has already been discussed earlier, but I got it after the update in September. Environment: the latest vs studio for mac, all the frameworks are updated, I also tried to switch to the preview channel, the error is the same. Actually the problem: after the update, the error of creating a native object began to appear.
From my renderer to - at Foundation.NSObject.InitializeObject (System.Boolean alloced) [0x0002e] in /Library/Frameworks/Xamarin.iOS.framework/Versions/13.8.2.2/src/Xamarin.iOS/Foundation/NSObject2.cs:196 at Foundation.NSObject..ctor (Foundation.NSObjectFlag x) [0x0000d] in /Library/Frameworks/Xamarin.iOS.framework/Versions/13.8.2.2/src/Xamarin.iOS/Foundation/NSObject2.cs:131 at UIKit.UIResponder..ctor (Foundation.NSObjectFlag t) [0x00000] in /Library/Frameworks/Xamarin.iOS.framework/Versions/13.8.2.2/src/Xamarin.iOS/UIResponder.g.cs:69 at UIKit.UIView..ctor (Foundation.NSObjectFlag t) [0x00000] in /Library/Frameworks/Xamarin.iOS.framework/Versions/13.8.2.2/src/Xamarin.iOS/UIView.g.cs:83
Error message: Could not create an native instance of the type 'xxx': the native class hasn't been loaded. It is possible to ignore this condition by setting ObjCRuntime.Class.ThrowOnInitFailure to false.
if set ObjCRuntime.Class.ThrowOnInitFailure = false; - native constructor returns null;
lib in Binding project is fat, all architectures are supported. i have no its code, only headers. ApiDefinition and Structs generated by sharpie, and works well.
mtouch options: --optimize=-remove-dynamic-registrar
please give some ways to solve, project is on fire..
If exist way to rollback all mono frameworks i can try, but its not good way.

Fody + Mono: the requested feature is not implemented

I'm trying to compile a C# project using Mono and am getting the following exception during compilation using xbuild:
Error: Fody: An unhandled exception occurred:
Exception:
The requested feature is not implemented.
StackTrace:
at Mono.Cecil.Mdb.MdbReaderProvider.GetSymbolReader (Mono.Cecil.ModuleDefinition,System.IO.Stream) <0x00017>
at Mono.Cecil.ModuleReader.ReadSymbols (Mono.Cecil.ModuleDefinition,Mono.Cecil.ReaderParameters) <0x000cb>
at Mono.Cecil.ModuleReader.CreateModuleFrom (Mono.Cecil.PE.Image,Mono.Cecil.ReaderParameters) <0x000e7>
at Mono.Cecil.ModuleDefinition.ReadModule (System.IO.Stream,Mono.Cecil.ReaderParameters) <0x00063>
at ModuleWeaver.GetTemplateModuleDefinition () <0x00133>
at ModuleWeaver.ImportAssemblyLoader (bool) <0x00027>
at ModuleWeaver.Execute () <0x00113>
at (wrapper dynamic-method) object.lambda_method (System.Runtime.CompilerServices.Closure,object) <0x0004c>
at InnerWeaver.ExecuteWeavers () <0x002cb>
at InnerWeaver.Execute () <0x00123>
Source:
Mono.Cecil.Mdb
TargetSite:
Mono.Cecil.Cil.ISymbolReader GetSymbolReader(Mono.Cecil.ModuleDefinition, System.IO.Stream)
(Hybrasyl)
The project is using Fody, which appears to be what's throwing the error. From what I can tell Fody should support Mono. I'm using the latest version of Mono (v4.0.1.0), Fody (v1.28.3.0), and Costura Fody (v1.3.3.0).
Q1: What feature is the compiler claiming is not implemented? I'm having trouble understanding the error message.
Q2: Is this expected behavior? I'm having trouble finding references to Fody's status with respect to Mono support and am not sure if this is truly missing support or whether I'm doing something incorrectly. I'm new to the .NET + Mono world so let me know if I need to clarify further.
Thanks!

TypeLoadException on startup

Recently started using Xamarin and MvvmCross. Busy building my first project. Created my .Core project and a ViewModel, installed the Nuget package in Visual Studio. Created my .Droid project, installed Nuget package. Created my first views and now trying to run the application. I however get the following exception:
Could not load type 'System.Runtime.CompilerServices.ExtensionAttribute' from assembly 'Cirrious.MvvmCross.Binding.Droid'.
Full stacktrace:
W/ ( 1438): Missing method .ctor in assembly /data/data/XamTest.Droid/files/.__override__/Cirrious.MvvmCross.Droid.dll, type System.Runtime.CompilerServices.ExtensionAttribute
W/ ( 1438): Can't find custom attr constructor image: /data/data/XamTest.Droid/files/.__override__/Cirrious.MvvmCross.Droid.dll mtoken: 0x0a000012
Unhandled Exception:
System.TypeLoadException:
E/mono ( 1438):
E/mono ( 1438): Unhandled Exception:
E/mono ( 1438): System.TypeLoadException: Could not load type 'System.Runtime.CompilerServices.ExtensionAttribute' from assembly 'Cirrious.MvvmCross.Droid'.
E/mono ( 1438): at XamTest.Droid.SplashScreen..ctor () [0x00000] in c:\Dev\XamTest\XamTest.Droid\SplashScreen.cs:16
E/mono ( 1438): at (wrapper dynamic-method) object.38e61b4f-1913-46a5-ba4a-75980457a823 (intptr,object[]) <IL 0x00018, 0x00053>
E/mono ( 1438): at Java.Interop.TypeManager.n_Activate (intptr,intptr,intptr,intptr,intptr,intptr) [0x0006a] in /Users/builder/data/lanes/monodroid-lion-bigsplash/0e0e51f9/source/monodroid/src/Mono.Android/src/Java.Interop/TypeManager.cs:141
E/mono ( 1438): at (wrapper native-to-managed) Java.Interop.TypeManager.n_Activate (intptr,intptr,intptr,intptr,intptr,intptr) <IL 0x0001e, 0x000a3>
E/mono ( 1438):
I/mono ( 1438): [ERROR] FATAL UNHANDLED EXCEPTION: System.TypeLoadException: Could not load type 'System.Runtime.CompilerServices.ExtensionAttribute' from assembly 'Cirrious.MvvmCross.Droid'.
I/mono ( 1438): at XamTest.Droid.SplashScreen..ctor () [0x00000] in c:\Dev\XamTest\XamTest.Droid\SplashScreen.cs:16
I/mono ( 1438): at (wrapper dynamic-method) object.38e61b4f-1913-46a5-ba4a-75980457a823 (intptr,object[]) <IL 0x00018, 0x00053>
I/mono ( 1438): at Java.Interop.TypeManager.n_Activate (intptr,intptr,intptr,intptr,intptr,intptr) [0x0006a] in /Users/builder/data/lanes/monodroid-lion-bigsplash/0e0e51f9/source/monodroid/src/Mono.Android/src/Java.Interop/TypeManager.cs:141
I/mono ( 1438): at (wrapper native-to-managed) Java.Interop.TypeManager.n_Activate (intptr,intptr,intptr,intptr,intptr,intptr) <IL 0x0001e, 0x000a3>
I/mono ( 1438):
Any ideas?
I need to mention that when I open my solution in Xamarin.Studio the reference to the Core library shows up as an error.
(- Incompatible target framework (.Net Portable Subset (.Net for Windows Store, .Net Framework 4.5, Silverlight 4, Windows Phone 7.5).).
This might just be another problem though, and not related to the exception.
Here's what worked for me when I had this exact same issue:
When I updated mvvmCross I still used an older version of Xamarin, which used an older version of monodroid. Updating Xamarin (new version uses monodroid 3) fixed the issue for me.
Hope this helps
The issue is related to the version of the Hot Tuna Starter pack I installed. I installed version 3.0.12.
When I replaced the Cirrious.MVVM and Cirrious.MVVM.Droid dll's located at packages\MvvmCross.HotTuna.MvvmCrossLibraries.3.0.12\lib\MonoAndroid16 with the dll's from the Hot Tuna Starter pack V3.0.9 everything started working fine. (I also tested 3.0.4 which worked fine too)
I did not test V3.0.10 and v3.0.11. I also tested v 3.0.13 BETA, but it is still broken.
Are you using Visual Studio 2012 and Xamarin latest from the stable branch?
Important: In Visual Studio, make sure you have latest NuGet manager by going to Tools menu \ Extensions and Updates \ Updates tab on the left.
I suggest you start over with a new test project and follow Exactly these steps:
a) Create a new Android app called MyApp.Droid, and a new PCL project MyApp.Core (target '.NET Framework 4.5' and 'Windows Phone 7.5 and above' - these are the minimum framework versions which MVVMCross works with)
b) Add the MyApp.Core as project reference to MyApp.Droid
c) Using NuGet, install 'MVVMCross Hot Tuna Starter Pack'. Make sure you have stable branch selected (there's a combobox at the top of the NuGet window)
Everything should compile and run fine.

system.entrypointnotfoundexception in <Filename unknown> in Unity3d

I am trying to call a simple native function (C++) from Unity3D. I have done the following:
Placed the libMSDKWrapper.so in Assets->Plugins->Android
This is my C# code
using UnityEngine;
using System.Collections;
using System.Runtime.InteropServices;
public class facebooktest : MonoBehaviour {
[DllImport ("MSDKWrapper")]
private static extern long getContextNative();
void Start () {
Debug.Log("Hello, World!");
long context = getContextNative(); // <-- Exception thrown here
Debug.Log(context);
}
}
I am getting the following exception:
system.entrypointnotfoundexception at [0x00000] in Filename unknown:0
I used the same libMSDKWrapper.so using java using the command
System.loadLibrary("MSDKWrapper");
and I was able to access and use the getContextNative() method.
Edit 1: I unzipped the contents of the apk and found that libMSDKWrapper.so file is present in test.apk/lib/armeabi-v7a
Edit 2: Here are the logcat logs.
03-25 11:40:17.543: D/dalvikvm(26176): Trying to load lib /data/data/com.disney.citygirl.goo/lib/libMSDKWrapper.so 0x41566348
03-25 11:40:17.568: D/MSDK(26176): Register Provider: SN_COMMUNITY
03-25 11:40:17.568: D/MSDK(26176): Register Provider: SN_FACEBOOK
03-25 11:40:17.568: D/dalvikvm(26176): Added shared lib /data/data/com.disney.citygirl.goo/lib/libMSDKWrapper.so 0x41566348
03-25 11:40:17.568: I/MSDK(26176): JNI_OnLoad called
03-25 11:40:17.573: D/dalvikvm(26176): Trying to load lib /data/data/com.disney.citygirl.goo/lib/libMSDKWrapper.so 0x41566348
03-25 11:40:17.573: D/dalvikvm(26176): Shared lib '/data/data/com.disney.citygirl.goo/lib/libMSDKWrapper.so' already loaded in same CL 0x41566348
03-25 11:40:17.598: I/Unity(26176): System.EntryPointNotFoundException: getContextNative
03-25 11:40:17.598: I/Unity(26176): at (wrapper managed-to-native) SocialAccess:getContextNative ()
03-25 11:40:17.598: I/Unity(26176): at SocialAccess.OnClick () [0x00000] in :0
03-25 11:40:17.598: I/Unity(26176):
03-25 11:40:17.598: I/Unity(26176): (Filename: ./Runtime/ExportGenerated/AndroidManaged/UnityEngineDebug.cpp Line: 43)
You are using a C++ plugin, but maybe your Unity3D version does not support it? I recall you need Pro to do that.
This page might provide a solution.
Make sure you are using the extern 'c' directive to avoid name-mangling issues. If you don't 'wrap' your calls in 'c' method names, you'll get this exact behavior because the c++ compiler 'mangles' or adds additional architecture-specific 'junk' to the method names. If you have questions, you can refer to my github project HERE
Focus on the main.cpp (the entry point which is the same in android-src/ as in the root). That is the pattern you will need to model your c++ dll after. This project will also show you how to build a c++ dll for android. Look at the README for full build instructions for both Ubuntu (and other Debian-like operating systems) and android.
#Virtlink I know its a pro-only feature, but it appears that Unity will just give a warning when using p/invokes. I'm not use if Unity fixed that in V4, but V3 allows you to use them anyways. The trial will also suffice.
Just as another note, is there a specific reason you NEED to use a C++ dll? In almost all cases, you can do what you want in managed C# code. Be absolutely sure you need this DLL as it will break cross-compatibility with a single codebase. With my dll, i decided to scrap my use-case for it and re-wrote the whole thing in c#.

MonoTouch 4.0 throwing ReflectionTypeLoadException using the simulator

Since updating a working MonoTouch 3.x app to MonoTouch 4.0, I have been getting the following error when attempting to start a Debug or Release build on the Simulator:
Unhandled Exception: System.Reflection.ReflectionTypeLoadException: The classes in the module cannot be loaded.
at (wrapper managed-to-native) System.Reflection.Assembly:GetTypes (System.Reflection.Assembly,bool)
at System.Reflection.Assembly.GetTypes () [0x00000] in <filename unknown>:0
at MonoTouch.ObjCRuntime.Runtime.RegisterAssembly (System.Reflection.Assembly a) [0x00000] in <filename unknown>:0
The problem appears to be with System.Xml.Linq, however I have checked all projects and references, and this doesn't even appear to be a transitive reference from what I can tell. I just don't appear to be using this anywhere.
Exception Message is always "Could not load System.Xml.Linq.XNodeNavigator from System.Xml.Linq".
Anyone have any ideas?
The root cause is that the iOS simulator only update files, it never deletes them (even if you delete your app from the simulator).
This cause problems if you have some files (e.g. System.Xml.Linq) at one point and remove them later (directly or use the linker which can remove it). From there you'll have some old, stale files in your simulator app directory.
The next issue is that MonoTouch register all assemblies present in the directory. This means the stale one are registered too in the simulator. At this stage this can work (and you won't see an error) or this could fail (with the error you have above) because the stale assembly does not have everything it needs to be loaded properly.
The easiest workaround is to reset your iOS simulator, that will remove everything (all apps and all files).

Categories