Search code examples
xamarin.iosxamarin.androidportable-class-library

Code works on Android and iOS - why can't I move it into a PCL?


I have a static class that uses

  • System.IO.Path
  • System.IO.Directory
  • System.IO.File.

Currently, the class is in my iOS project and unchanged also in my Android project.

I created a PCL that targets Android and iOS only.

However, neither one of the namespaces is available.

I presume that is because iOS and Android alone are not suitable for a PCL profile and that's why Windows Store 8 or Silverlight 5 gets added and that removes the System.IO.* namespaces.

Is this working as designed? Is file linking my only chance in this case?


Solution

  • Yes, for now this is the way it's supposed to work. You can use something like my PCL Storage library to access the file system from a PCL, or you can simply use file linking.

    As a side note, I'd recommend choosing Windows Store and .NET 4.5 along with the Xamarin targets. That profile is going to give you more APIs than the one which targets Silverlight 5 which you get by default when you just choose Xamarin platforms in that dialog.