API methods available in Xamarin Forms Portable project (Droid, iOs, Portable) RRS feed

  • Question

  • User207211 posted


    Hope somebody can help shed some light on this:

    In Visual Studio 2013 (VS) when I create a Blank App (Xamarin.Forms Portable) Project (default settings) I experience the following:

    E.g. Class System.Net.IPAddress is available in the Droid Project class MainActivity & in the App1.iOS Project class AppDelegate.cs but NOT in the App1 (Portable) project class App.cs.

    Why is this so?

    Friday, July 29, 2016 5:33 PM


All replies

  • User2148 posted

    Probably because it's not a PCL API. You have to use it in its own project and call in PCL via DependencyService. For example, alse System.IO has not all methods in PCL...

    Friday, July 29, 2016 5:59 PM
  • User207211 posted

    @AlessandroCaliaro| Thanks for your answer! I thought that any API Function that is available in the union of all platforms would be available in the PCL project as well: Doesn't that make sense?

    I am not familiar with how to use DependencyService. I see that DependencyService provides the Register and Get methods...

    How can I use DependencyService to create an instance of e.g. IPAddress in the Portable part of the project?

    Could you provide an example please?

    Friday, July 29, 2016 6:42 PM
  • User2148 posted

    Take a look at this sample


    In PCL you have to create an interface, then, in every platform, you have to create a class that implement the interface.

    Friday, July 29, 2016 6:46 PM
  • User2148 posted

    then in PCL you can use methods calling the DependencyService


    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Friday, July 29, 2016 6:47 PM
  • User207211 posted


    Thanks for your pointers: I am starting to understand the DependencyService concept now! Will read more up on it.

    Friday, July 29, 2016 7:01 PM
  • User275457 posted

    When any event or method triggered on some action (like button pressed) in Droid Project then is it possible to get this same event at the same time triggered in the Portable project ( in Xaml Forms) using Dependency Services?

    Wednesday, December 7, 2016 11:58 AM