views:

246

answers:

3

Why doesn't Windows Phone 7 fully support the C# specification when the only language available to it is C#? Okay, I can understand the lack of "dynamic" support, but why isn't contra-covariance supported? Why aren't third-party libraries that are familiar to us and that we use in server-desktop projects not compatible with the Phone 7? What's sense in an having an intermediate IL code if we still end up here?

+6  A: 

Windows Phone 7 doesn't fully support all of the .NET Framework features you are used to because it is built on Silverlight.

Silverlight was designed to not support the full set of features because it is meant to be a light runtime (rather than requiring every user to download the entire .NET Framework to run a Silverlight appliction).

Justin Niessner
+7  A: 

Bear in mind that it's running on the Compact Framework CLR - which doesn't have all the features of the desktop CLR.

EDIT: After a bit of trawling, I've found that generic variance isn't supported in the Compact Framework (or at least wasn't back in 2005, and I suspect it hasn't been implemented since as there's been little use until very recently):

No support for variance modifiers. Though variance/co-variance forms part of the overall ECMA spec for generics, and is implemented for the full .NET CLR, it is not used in Base Class Library or by C# and VB.

Okay, so it doesn't "fully support" C# 4 (the absolutely latest release), but do you know of any C# 3 language features which aren't supported?

In terms of libraries, you're dealing with a framework which is roughly based on Silverlight 3 but with some Silverlight 4 bits, and with various aspects of "desktop" Silverlight removed. (EDIT: According to a link in the comments, it should contain all of the APIs of Silverlight 3. I'm not sure whether that's accurate or not...) In other words, it's its own beast, really. Even though the IL itself may be portable, it's hard to give a guarantee of compatibility when various APIs have been removed. However, in many cases you can rebuild the libraries to target WP7. I agree it's annoying to have to do so, but it's better than them not being available at all.

EDIT: Citations for my claims that it uses the CF CLR:

Windows Phone 7 Series Developer General FAQ:

What technologies and tools can I use to program for Windows Phone 7 Series?
You can currently use the managed language C# using Silverlight and XNA based on Compact Framework.

Can I use Windows Forms?
No, Windows Forms are not supported in the version of Compact Framework included with Windows Phone 7 Series.

(and later)

Can I use XNA library calls in Silverlight?
Silverlight and XNA share a common code base in the Compact Framework. If a call is not GUI based, in most cases it can be shared between Silverlight and XNA.

A CF team member's blog post:

For the developers coming to Windows Phone 7 (WP7) from the Windows desktop let me first clarify that the runtime (CLR) that is running on the WP7 is not the same as the one running on the desktop. The WP7 runtime is known as .NET Compact Framework (NETCF) and it works differently than the “desktop CLR”.

Jon Skeet
and what about existing libriries and sence of IL?
sfedorov1982
It's running on Silverlight for Windows Phone, which is neither CF nor Silverlight 3 or 4. It's missing lots of functionality which is present in .NET CF ( I am talking mostly about the library), so calling it CF-based is misleading.
Eugene Mayevski 'EldoS Corp
@Eugene: The CLR is the Compact Framework CLR, rather than the normal CoreCLR of Silverlight though. I'll edit to clarify.
Jon Skeet
Nope, it's not cf, it was on windows mobile 6.5, but not on windows phone 7. I've just realised I've voted down Jon Skeet! Hmmm... maybe I'm wrong.
Christopher Edwards
@Christopher: I'll look for the evidence now... I'm 99% sure I'm right on this. (Bear in mind I'm talking about the CLR here, not the libraries.)
Jon Skeet
@christopher - zomg!
Robaticus
@Robaticus: I think I've no given fairly ample evidence that it *is* the CF CLR on WP7. It's not the traditional CF libraries, but then that was true of the CF on XBox too...
Jon Skeet
@Jon Skeet - You're right. .NET Compact Framework (NETCF) is what runs on Windows Phone 7 devices. I assumed the OP was referring to library calls rather than actual differences between the CLRs though.
Justin Niessner
@Jon: I found this far less authoritative resource - http://gregdoesit.com/2010/03/windows-phone-7-and-silverlight-details-revealed/ - but it seems you are correct :)
Christopher Edwards
@Justin: Well, all aspects of it make a difference. The fact that it's just not the desktop platform (whether CF or Silverlight) is what stops 3rd party libraries from just working - and the fact that it's the CF CLR stops generic variance from working.
Jon Skeet
@Jon - I was just "zomg-ing" that you got voted down. Whether right or wrong, it makes us aspirants remember you're human. `<wink/>`
Robaticus
@Christopher: I'm not sure whether Scott's gone back on what he said before, but I'm *reasonably* sure there are elements of Silverlight 3 which aren't in WP7. I'm not a Silverlight expert, but that's my understanding of things based on workarounds I've had to find :)
Jon Skeet
No, I'm now sure you are correct, +1.
Christopher Edwards
@Justin At least in some respects the WP7 CLR is simply different from the NETCF CLR. I had an issue recently where hand-crafted, but ECMA-compliant, IL-code was rejected by the WP7-loader. All other CLRs (desktop, NETCF, Silverlight) and peverify accepted it. The response from MS was that "NetCF IL Verifier implementation which runs on WP7 is more restrictive than ECMA rule requires". Quite surprising - but most of all annoying to have valid code rejected.
Richard Flamsholt
A: 

if you're using SL, linking to a webservice, then you can (should) keep the mobile app skinny and suck the fat on the server...

sounds simple i know, but many peeps TRY to delegate all responsibilities to the 'app' - this is bad practice. if your 'website' is REST compliant, then you should align your app to purely making json/xml calls to your 'expensive' server based logic.

anyway, that's how we do it :)

jim
Sure, but how does this relate to the fact that the question is about the C# implementation on WinPhone?
ctacke