c# - Xamarin.Forms DependencyService Get() Method Returns Null in PCL -


i have latest xamarin alpha installed , can't uwp , dependencyservice working.

in uwp project have:

forms.init(e);  // release version, doc said debug dependencyservice.register<specialinterface>(); iinterface1 iinterface1 = dependencyservice.get<iinterface1>(); 

this find interface pointer.

in pcl have:

iinterface1 iinterface1 = dependencyservice.get<iinterface1>(); 

in view model contained in pcl (after button click) fails returning null value get<iinterface1>() call on both uwp , android.

here implementation contained in uwp project:

using prismunityapp2.uwp; using sharedproject1; using xamarin.forms;  [assembly: dependency(typeof(specialinterface))]  namespace prismunityapp2.uwp {     public class specialinterface : iinterface1     {         public specialinterface() { }          public int testmethod(int i)         {             return i;         }     } } 

finally, interface defined in shared project follows:

namespace sharedproject1 {     internal interface iinterface1     {         int testmethod(int i);     } } 

i have sample "usingdependencyservice" working in android, winphone fails because hyperv off android.

what missing?

thanks help.

using following packages/versions:

  • prism.unity.forms 6.2.0.pre4
  • prism.forms 6.1.0.pre4
  • xamarin.forms 2.2.0.45
  • unity 4.0.1
  • windows 10 uwp

    public void onnavigatedto(navigationparameters parameters) {     if (parameters.containskey("title"))         title = (string) parameters["title"] + " , prism";      iinterface1 iinterface1 = dependencyservice.get<iinterface1>();     if (iinterface1 != null)     {         int value = iinterface1.testmethod(1);         title += " ::: " + value;     } } 

the dependencyservice.get<iinterface1>() call returning null in pcl because it's looking different version of iinterface1 being defined multiple times.

because iinterface1 located in shared project that's referenced both pcl project , uwp & android projects, it's same creating interface separately in both pcl , app projects same name , signature. parent assembly different however.

if move iinterface1 existing pcl or separate pcl referenced both existing pcl , app projects, dependencyservice should able locate platform specific implementation, specialinterface, expected.


Comments

Popular posts from this blog

sequelize.js - Sequelize group by with association includes id -

android - Robolectric "INTERNET permission is required" -

java - Android raising EPERM (Operation not permitted) when attempting to send UDP packet after network connection -