2

I want to make a call to Thread.Sleep in my Portable Class Library project. This method is implemented in the Mono libraries of my iOS and Android projects, so in theory, I should just choose a compatible PCL profile. However, this is proving to be more difficult than it should be.

How do I determine which PCL profiles contain the library implementations that I need, and how do I tell Visual Studio to reference that specific profile?

I haven't been able to find any documentation on MSDN which even acknowledges that PCL profile numbers exist let alone how to choose a particular one. The only option I have at the moment is to manually reference the System.dll in the profile folder, but this feels like walking into a mine field. Any help is appreciated.

jsumrall
  • 111
  • 7
  • This is pretty fundamentally not how PCL works. You choose your targets, then you find out what is supported. It never makes sense to pick arbitrary targets. Plenty of ways to substitute Thread.Sleep(), you can use Task.Delay() or ManualResetEvent.WaitOne(). – Hans Passant May 27 '15 at 17:26

2 Answers2

1

This blog post documents all available PCL profiles as of VS2015 Update 3.

For quick reference, following are some of the profiles.

  • Profile7 - .NET Framework 4.5 & Windows 8.0
  • Profile24 - .NET Framework 4.5 & Silverlight 5.0
  • Profile47 - .NET Framework 4.5, Silverlight 5.0 & Windows 8.0
  • Profile78 - .NET Framework 4.5, Windows 8.0, Windows Phone Silverlight 8.0
  • Profile158 - .NET Framework 4.5, Silverlight 5.0, Windows 8.0, Windows Phone Silverlight 8.0
  • Profile255 - .NET Framework 4.5, Silverlight 5.0, Windows 8.0 & Windows Phone 8.1
  • Profile344 - .NET Framework 4.5, Silverlight 5.0, Windows 8.0, Windows Phone 8.1, Windows Phone Silverlight 8.0

As a side note,

  1. This Xamarin documentation will give you an idea about what a PCL is.
  2. This SO answer tells how to change the PCL profile.
Curiosity
  • 1,753
  • 3
  • 25
  • 46
-1

There is no way to do so unless someone writes a utility out like a search engine across all presented PCL profiles.

And your description of "This method is implemented in the Mono libraries of my iOS and Android projects" shows several spots of misunderstanding,

  1. It is Xamarin libraries, not Mono. The two brands are not equivalent to each other.
  2. This method might be available in Xamarin.iOS and Xamarin.Android, but just fails to be used in PCL due to Microsoft side's rude decision initially. Simply keep this in mind and you will see why if you later learn more about how PCL works under the hood and what defines a PCL profile.

So if you do want to use every bits, a shared asset project is preferred.

More info can be found at Xamarin,

http://developer.xamarin.com/guides/cross-platform/application_fundamentals/pcl/introduction_to_portable_class_libraries/

Lex Li
  • 60,503
  • 9
  • 116
  • 147
  • I definitely don't understand PCL and appreciate any clarification you can provide. As I currently understand it, the Xamarin.iOS and Xamarin.Android projects in VS all reference the Mono libraries and all PCL references are replaced with Mono during linking. However, I can't find any documentation/explanation of what is actually going on during the build. It's all very black box. Could you point me to a resource which describes how Xamarin uses a PCL to build a cross-platform application? – jsumrall May 28 '15 at 18:12
  • Added a link to Xamarin and there are more from them. – Lex Li May 29 '15 at 00:24
  • I'm familiar with that page of Xamarin's documentation, but I'm looking for something more technical. The inclusion of the PCL reference and the MonoTouch reference represent two redundant implementations of the .NET framework. How is this redundancy resolved during the build process? Are both implementation included? Is one replaced with the other? – jsumrall May 29 '15 at 15:25
  • 1
    That technical detail might appear in a book like CLR via C#. Or you simply assume the code is compiled against the PCL profile, while at runtime the actual types come from Xamarin.iOS assembly. Type forwarding is the term for that magic. – Lex Li May 29 '15 at 15:31
  • Interesting. So, the MonoTouch references in my iOS project may actually be type forwarding to the PCL. – jsumrall May 29 '15 at 15:37
  • Forwarded from, not forward to. The runtime has no access to the PCL profiles at all. Those profiles are only used by the compiler. – Lex Li May 29 '15 at 15:40