What’s this .NET Compact Framework thingy?

Bidar - On the way back to hyderabad

If you are following the latest Windows Phone stories than you have surely heard about the .NET Compact Framework (NETCF) which is the core managed runtime used by the Windows Phone 7 programming model. This is an implementation of the .NET specification that works on devices and a disparate combination of HW and SW.


In case you are hearing about NETCF for the first time, then hopefully this post will help you to understand it’s architecture and how it is different from the desktop .NET.

The Architecture

At the heart of NETCF is the execution engine. This contains the usual suspects including the JIT, GC, Loader and other service providers (e.g. Marshalling that marshals native objects to managed and vice versa, type system).

The entire Virtual machine is coded against a platform agnostics Platform Abstraction Layer or the PAL. In order to target a platform like say Nokia S60 we implemented the PAL for that platform. Stringent policy of not taking any platform dependency outside PAL and ensuring in PAL we only use features that are commonly available on most modern embedded OS allows NETCF to be highly portable. Currently the PAL supports a variety of OS and processor architecture. The ones in Red are those that are used for Silverlight, the others are available for the legacy .NETCF 3.5.

The other system dependent part is the JITter which compiles the MSIL into the platform dependent instructions. For every supported processor architecture there’s a separate implementation of JIT.

This entire runtime is driven by a host. E.g. for Silverlight on S60 it’s the Silverlight host running as a plugin inside the Nokia browser, on Windows Phone it’s the Windows Phone task host. These hosts uses the runtime services to run managed code. The host interacts with the runtime over the hosting interfaces.

Managed code can either be the framework managed code like BCL and other Silverlight/XNA framework managed code or the user code that is downloaded from the web/application-store. Even though the framework managed code can interact with the underlying system including the execution-engine and the OS (via Platform-Invoke) the user managed code is carefully sandboxed. If you see the arrows moving out of the user managed code it is evident that user managed code can call only into the framework managed code (which in turn can call into the system post security verification). User code is not allowed to access any native resources (including P/Invoke).

The host knows about the UI and it’s rendering and uses reverse Invoke to call into the managed code. E.g. if a user clicks on a XAML button the Silverlight host using the XAML object tree and rendering logic (hit-testing) figures out which object got clicked on and it uses reverse-pinvoke to call into the corresponding managed objects (which provides the event handler). That managed code is then verified, security checked, jitted and run by NETCF.


NETCF is highly portable. As far as I know it’s one of the very few (or is it the only one :)) runtime shipping out of Microsoft that supports Big-Endian processor architecture (Xbox360 uses Big-Endian processor). It is designed for resource constrained devices and is battery friendly. For many time-space trade-offs it tilts towards conserving space (e.g. Code-pitching which I’ll cover later) and at the same time works well on Xbox360 running high-end games. The list of processor/OS I have given above is just illustrative and it actually works or there are POC (proof-of-concept) of it working on really esoteric SW+HW combinations.

Some CF Facts

  1. Design Goals
    1. Keep the runtime highly portable, that is the main NETCF USP
    2. Designed for resource constrained devices
    3. Battery friendly (use less power)
  2. Nothing comes for free. The above design results in some unique NETCF features (more about that later) and some limitations as a consequence.
  3. Some of the well known platforms powered by NETCF runtime is Windows Mobile 6.5 and below, Windows Phone 7, XNA (on Xbox 360), Zune, Media Room (pdf), Silverlight on Nokia S60.
  4. Currently shipping versions are 3.7 on Windows Phone and 3.5 elsewhere.
  5. Windows Phone runs on both ARM (the real phone devices) and x86 when running on the emulator (which is a x86 VM). NETCF becomes a natural choice because it runs on both these processors.
Comments (13)
  1. Curt says:

    Nice article. It might be nice to hear about how NETCF’s mark-and-sweep GC affects design and development of apps, any guidance in that area?

  2. Hi! Great article. I’d like to translate portions of it to spanish and publish it in my blog, of course, preserving the credits 😀

    There is no many authoritative sources in spanish, and we’re always looking for serious tech info to share with our community. Can I do it? Any restrictions?


    Carlos A. Pérez

    MVP Devices App. Development

  3. Carlos anything for a MVP, do go ahead.

  4. Curt, I own the netcf GC so sure it’s coming.

  5. jo says:

    Hi ! Thanks for your article.

    I wonder whether a new version of WinCe will be used to build WP7. Indeed I’m OEM and I would like to use CF 3.7 with new Silverlight possibilities (managed framework) but I’m currently using WinCE 6.0 R3. Maybe it is not compatible ? Does Microsoft plan to release WinCE 7.0 that includes NETCF 3.7 ?

  6. Jo the current NETCF 3.7 is targetter only for Windows Phone. The future roadmap on WinCE is yet to be worked out.

  7. Regis Vaquette says:

    Can you explain what the attribute FrameworkVisibilityCompactFrameworkInternalAttribute will be used for?

    Will the WP7 platform support a pure Compact Framework mode, or another new platform (… or else a future Windows Mobile 6.X version) ?

    Thanks a lot in advance for your answer.

  8. jinishans says:

    BTW, what ver of NETCF is running in Kin one/two the same as above..?

  9. Jinishans, frankly I don’t really know

    There are too many places NETCF runs for me to keep track off 🙂

  10. Steve Wilkinson says:

    With the .NET CF now being at the core of Silverlight and XNA does the .NET CF still exist in its traditional form ie. managed code development for Windows CE devices ?

    We have a massive estate of Windows CE powered devices running .NET CF applications,  these applications talk to and control a variety hardware through p/ivnvoked  mechanisms.  I've heard that .NET CF will no longer support features such as p/invoke, IO and database access (ADO.NET).  Can you confirm or deny this ?

    Are we likely to be able to suport this going forward or should we start looking at Linux ?

  11. WinCE in need says:

    I second the need for a NETCF update in WinCE.  Have we worked out when NETCF 3.7 will come to WinCE?  We sure could use generational GC…

  12. Tom says:

    So what is the current state of .NET Compact Framework? Will there be any next version of it?

Comments are closed.

Skip to main content