Not every library will work on Windows Phone 7
Join the DZone community and get the full member experience.Join For Free
As obvious as this might seem, there are still lots of questions online from people asking whether it is possible to use general .NET-targeted libraries in Windows Phone 7. The common misconception here is that if a library is built on top of the .NET Framework, it should work in any .NET project regardless of the platform.
As good as this might sound, it is not entirely true. Although the fundamentals of the framework still apply, like the base types, a lot of functionality will be different (e.g. missing methods or classes), and there is a reason for that. Developers at Microsoft did not remove functionality for the sake of minimizing the set of available tools. The main reasons for this are:
- Performance - some classes and the associated calls have a significant impact on system resource consumption levels, therefore using them on a mobile platform would not be a good idea because mobile devices have limited capabilities. For a good example, take a look at methods asociated with HttpWebRequest, WebClient or with a passed service instance. When it comes to data consumption, those are all asynchronous and synchronous methods are either removed completely or have their async implementation.
- Security - specifically, this applies to cross-domain and device security. For example, you cannot access the filesystem on the phone the same way you did when you were developing desktop or even web applications. This is introduced to protect other applications (and the OS itself) from tampering and piracy. Another example could be the fact that you cannot directly load a XML file in XDocument right from the web - only local paths are acceptable.
That being said, since Windows Phone 7 is lacking specific "big machine" functionality like databases (SQL and non-SQL), you cannot access the System.Data namespace and all external database access should be done via web services. This applies to lots of other namespaces as well (e.g. System.Xml, whcih in fact is much more limited on WP7).
You should also remember that if a library is not listed in the References dialog by default (e.g. System.Json) this doesn't yet mean that you cannot use it on the phone. Some additional libraries are located in the Silverlight SDK folder on your local machine and you should check that location (I wrote about this possibility here).
So what exactly can you do to make sure that a specific library works in a Windows Phone 7 application?
The best option is if the library was originally built as a Windows Phone 7 library. Other than that, an alternative would be building a Silverlight library. However, remember that even if you are able to add a library to your project, this does not mean that it will work. Be very careful because some calls will show themselves as non-functional only when called - no compile-time error will ever be thrown. Therefore it is a good idea to stress-test the library to the maximum before distributing it.
When you are building libraries from source, make sure that all correct references are used (you can use the Class Library documentation to check this).
Opinions expressed by DZone contributors are their own.