Reputation: 4355
This exact same code works fine in another solution, but not in this one, so I suspect it's a configuration issue.
My solution is: - XamForms PCL - Android project - PCL library (wtih INativeMethods) - Android library (with NativeMethods implementing INativeMethods)
This is my interface in the PCL library:
namespace DreamzLibs
{
public interface INativeMethods
{
}
}
This is the implementation in the Android library:
[assembly: Dependency(typeof(NativeMethods))]
namespace DreamzLibs.Droid
{
public class NativeMethods : Java.Lang.Object, INativeMethods
{
}
}
This is where it's requested:
public static Lazy<INativeMethods> NativeMethods = new Lazy<INativeMethods>(() => DependencyService.Get<INativeMethods> ());
This is the error I get:
[MonoDroid] UNHANDLED EXCEPTION:
[MonoDroid] System.TypeInitializationException: An exception was thrown by the type initializer for Boats.App ---> System.TypeLoadException: Could not load type 'DreamzLibs.Droid.NativeMethods' from assembly 'DreamzLibs.Droid, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null'.
[MonoDroid] at System.Reflection.MonoCMethod.InternalInvoke (System.Object obj, System.Object[] parameters) [0x00023] in <filename unknown>:0
[MonoDroid] at System.Activator.CreateInstance (System.Type type, Boolean nonPublic) [0x000af] in <filename unknown>:0
[MonoDroid] at System.Activator.CreateInstance (System.Type type) [0x00000] in <filename unknown>:0
[MonoDroid] at Xamarin.Forms.DependencyService.Get[INativeMethods] (DependencyFetchTarget fetchTarget) [0x00076] in <filename unknown>:0
[MonoDroid] at DreamzLibs.Utils.<.cctor>b__2 () [0x00000] in e:\Code\Boats\DreamzLibs\Utils.cs:25
[MonoDroid] at System.Lazy`1[DreamzLibs.INativeMethods].CreateValue () [0x00075] in <filename unknown>:0
[MonoDroid] --- End of inner exception stack trace ---
[MonoDroid] at Boats.Droid.MainActivity.OnCreate (Android.OS.Bundle) [0x0005d] in e:\Code\Boats\Droid\MainActivity.cs:37
[MonoDroid] at Android.App.Activity.n_OnCreate_Landroid_os_Bundle_ (intptr,intptr,intptr) <IL 0x00013, 0x0008e>
[MonoDroid] at (wrapper dynamic-method) object.57e490e4-6d7f-42bb-8d74-c204b5bfcb8e (intptr,intptr,intptr) <IL 0x00017, 0x00027>
[art] JNI RegisterNativeMethods: attempt to register 0 native methods for md52ce486a14f4bcd95899665e9d932190b.JavaProxyThrowable
Upvotes: 0
Views: 981
Reputation: 4355
Had to re-install package "Microsoft.Bcl" to solve this issue..
Upvotes: 1