Freigeben über


Why Doesn't My Desktop App Work on CF (Anymore)?

The Desktop Framework and the CF Framework have different Public Key Tokens as part of their strong name.  The Desktop framework commonly uses two different Key Tokens (b77a5c561934e089 and b03f5f7f11d50a3a), while CF currently uses one (969db8053d3322ac).  CF does not map Desktop references to CF assemblies, so any application referencing Desktop assemblies should never work on the Compact Framework because the references can not be resolved at run time.

“Never?!?” you say?  Well, okay, not exactly never.  There are two exceptions.

The first exception is mscorlib.dll.  Currently, all shipping frameworks (including the Desktop framework) treat any references to any mscorlib as a reference to their own mscorlib.  There are multiple reasons for this, but the primary reason is that without mscorlib, an app can not even generate a managed exception, as all the basic types and exception types are housed in mscorlib.  Therefore, any app which uses things housed entirely within mscorlib should work on any .NET Framework.  That said, this is not a supported scenario and there are still cases where it will fail to work.  Primarily, there are things that exist within the Desktop's mscorlib that are not supported on CF.  A reference to something not supported on CF will still cause the app to fail when run against CF.

The second exception is a bug that existed both in V1, and V1SP1 of CF, but was fixed in V1SP2 (and will remain fixed moving forward).  This bug allowed, under certain circumstances, Desktop references to be retargetted to CF assemblies if the CF assembly was already loaded.  This would happen for instance if, in a DLL, you referenced the Desktop System.Windows.Forms, but loaded the CF System.Windows.Forms in the application before using the DLL.  Unfortunately, the way that Visual Studio .NET 2003's “Add New Project” wizard is structured, it is very easy to add a Desktop Class Library to a CF Project, so several applications were broken by this bug fix.  To add a CF Class Library to an existing CF Project, remember to select “Smart Device Application”, and then select “Class Library” on the first pane of the Wizard.

-- jeh

Disclaimer:
This posting is provided “AS IS” with no warranties, and confers no rights

Comments