Why can't I reference System.Net.Sockets in a Portable Class Library using Xamarin?

*爱你&永不变心* 提交于 2019-12-18 16:40:08

问题


I am trying to use System.Net.Sockets API in a portable class library so that my projects can reuse code for socket connections. But I cannot reference that namespace in my code.

As I understand it, PCLs limit you to assemblies that are available on all targeted platforms. But I am targeting ios, Android, and .Net 4.5 (using Xamarin), and all of these should have the system.dll assembly that contains the API. What am I missing?


回答1:


As it is right now, there is no PCL profile targeting only

  • .NET Framework (4/4.03/4.5/4.5.1)
  • Xamarin.Android
  • Xamarin.iOS

If you for example attempt to define a Portable Class Library with only these targets, the project PCL profile will automatically add the Silverlight 5 target:

Even though Silverlight 5 itself does support some of the System.Net.Sockets namespace types, none of these types have been transferred to any PCL profile. As far as I can tell, the PCL System.Net functionality is limited to HTTP networking.

For example, if .NET Framework 4.5 is selected, this will correspond to PCL profile 24, for which the System.Net.dll contents are as follows:




回答2:


Using advanced PCL development AKA "Bait and switch" you may be able to do this

see link



来源:https://stackoverflow.com/questions/24045075/why-cant-i-reference-system-net-sockets-in-a-portable-class-library-using-xamar

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!