Partager via


Differences Between the .NET Compact Framework and the .NET Framework

[This documentation is for preview only, and is subject to change in later releases. Blank topics are included as placeholders.]

The .NET Compact Framework is a subset of the full .NET Framework. It implements approximately 30 percent of the full .NET Framework class library and also contains features and classes that are specific to mobile and embedded development.

This topic does not describe all the differences between the two Frameworks, but lists the important considerations for developing applications.

Application Domains

The .NET Compact Framework does not currently support loading assemblies into a domain-neutral code area for use by multiple application domains. For more information, see Application Domains in the .NET Compact Framework.

Arrays

Although some languages support lower bounds other than zero, the common language runtime (CLR) does not and throws a MissingMethodException if the first element is not zero.

ASP.NET

The .NET Compact Framework is primarily a rich client platform and does not provide ASP.NET support. To develop Web pages for mobile devices, you can use ASP.NET mobile Web controls. To develop Web pages for personal computers or Web service providers, see your ASP.NET documentation.

Assemblies and File Formats

Applications for both Frameworks use assemblies. Both Frameworks access portable executable (PE) files, which contain the Microsoft intermediate language (MSIL) and metadata that define a .NET Framework application. A PE file can refer to a programming namespace that is defined and shared by other assembly files. See Binary Compatibilities with the Full .NET Framework for more information.

Assemblies and Global Assembly Cache

The .NET Compact Framework does not currently support multi-module assemblies, but does support satellite assemblies.

Classes and Types

The .NET Compact Framework supports a subset of the .NET Framework class library. This subset is appropriate for applications that are designed to run on resource-constrained devices and is semantically compatible with same-named classes in the .NET Framework.

For information about how to determine .NET Compact Framework support, see How to: Find Supported Members of the .NET Compact Framework in the Class Library.

COM Interop

For information about COM interop and marshaling differences between .NET Compact Framework and the full .NET Framework, see Interoperability in the .NET Compact Framework.

Common Language Runtime

The common language runtimes in both Frameworks benefit from managed code execution, just-in-time (JIT) code compilation, and garbage collection. They support the Common Language Specification (CLS).

Both Frameworks have built-in primitive types as well as other types that you can use and derive from when you build your application.

The common language runtime for the .NET Compact Framework is approximately 12 percent the size of the full .NET Framework common language runtime.

Controls

The .NET Compact Framework supports most of the Windows Forms controls provided by the full .NET Framework and contains controls that are specific to the .NET Compact Framework.

Windows Forms controls are specially built for the .NET Compact Framework. For more information, see Controls in the .NET Compact Framework.

Current Directory

The functionality of a current directory is not present in the Windows Embedded CE operating system. Therefore, the .NET Compact Framework does not support the GetCurrentDirectory and SetCurrentDirectory methods.

The .NET Compact Framework supports the WorkingDirectory property for a ProcessStartInfo object. However, its context is not preserved by the running executable in subsequent launches and file loads.

Data

The .NET Compact Framework provides a subset implementation of ADO.NET and includes the SQL Server Mobile data provider. The System.Data.OleDb namespace is not supported. For more information about data support, see Data Access and XML Support in the .NET Compact Framework.

Data Types and Floating-Point Precision

The .NET Compact Framework does not support the MidpointRounding enumeration.

In a division calculation, if the divisor is very large or at the maximum floating-point value, or it is very low or at the minimum floating-point value, the calculation returns 0 (zero) instead of the correct calculation.

The MIPS platform does not support the full precision specified by the Standard for Binary Floating-Point Arithmetic (IEEE 754), and can cause unpredictable results. Because of performance considerations, the .NET Compact Framework does not provide a floating-point emulation capability for this platform.

Delegates

Asynchronous delegates, specifically BeginInvoke and EndInvoke methods, are not supported. For more information, see Asynchronous Programming Using Delegates.

Deploying Applications

To deploy an application, you can easily copy the assembly to the target device by using a cable from the desktop computer, its infrared port, or a wireless Internet or intranet connection. In Microsoft Visual Studio 2005, you can deploy directly to the device while debugging.

Diagnostics Tracing

The .NET Compact Framework does not support configuration files for tracing, but you can use performance counters. For more information, see Performance and Diagnostics in the .NET Compact Framework.

Disposed Objects

The full .NET Framework does not guarantee that accessing properties or methods on a disposed object will always succeed. However, accessing some properties such as Text often does succeed on the .NET Framework. Because of implementation differences between the two Frameworks, accessing methods or properties on a disposed object will almost always fail on the .NET Compact Framework.

Encoding and Localization

Localization (globalization) support, such as date formatting and sort tables appropriate for the locale, defers to the underlying operating system whenever possible for compatibility and size efficiency.

The .NET Compact Framework depends on the operating system for sorting data. Therefore, sorting may produce unexpected results for some cultures.

The .NET Compact Framework does not support per-thread CurrentUICulture settings.

For more information about localization support, see Encoding and Localization in the .NET Compact Framework.

Events

The .NET Compact Framework supports the GotFocus and LostFocus events, but does not support the Deactivated event.

Exception Description Strings

The .NET Compact Framework provides exception error message strings in a separate DLL called System.SR.dll to save memory.

You can also provide exception strings for other cultures to localize applications.

File Names and Paths

Windows Embedded CE resolves a file name that is specified without path information as being in the root directory of the device, not in the application directory. To ensure successful operations, specify absolute path information.

The .NET Compact Framework processes Uniform Resource Identifier (URI) strings prefixed by file:// differently from the full .NET Framework. A relative specification such as file://myfile resolves as \\myfile. The URI string file:///myfile (with three forward slashes) resolves as \myfile in the root directory.

You can get the version of an assembly with the Version property, but its support depends on the manufacturer of the device and cannot be guaranteed.

To get the name of the directory that contains an application, see How to: Get the Application Directory.

High Resolution

In the .NET Compact Framework 2.0 and later versions, DPI resolution is automatically handled in Visual Studio projects. For more information about high resolution, see How to: Handle Orientation and Resolution Changes.

Input/Output (I/O)

Because of differences in device operating systems, there are constraints and restrictions on the I/O model. The .NET Compact Framework does not provide file change notifications.

Because device I/O occurs in RAM, file and directory attributes cannot be set or accessed.

Installation and CAB Files

You can use CAB files and create Microsoft Windows Installer applications to distribute your applications.

Languages

The .NET Compact Framework supports development using Visual Basic and Visual C#, but does not currently support C++.

Math

Not all math methods are supported on all device platforms; however, they are included in the API for compatibility.

Memory

The .NET Compact Framework is optimized for battery-powered systems and avoids heavy use of RAM and CPU cycles. For more information about how to save memory, see Device Memory Management in the .NET Compact Framework and How to: Improve Performance.

Networking

The .NET Compact Framework provides Infrared Data Association (IrDA) classes for making infrared connections and Web listening classes for servicing HTTP requests to the device. These classes are available only in the .NET Compact Framework. For more information, see Networking and Connectivity in the .NET Compact Framework.

Proxy Code

The .NET Compact Framework does not support all the code generated by the Web Services Description Language Tool (Wsdl.exe). To determine which code is not supported, see How to: Use a Proxy Generated by Wsdl.exe.

Reflection

The .NET Compact Framework does not support the System.Reflection.Emit namespace.

The .NET Compact Framework does not currently support the equality operator (==) when it compares reflection objects such as MethodInfo, FieldInfo, PropertyInfo, EventInfo, MemberInfo, MethodBase, ConstructorInfo, and ParameterInfo. As an alternative, see Implementing the Equals Method.

Remoting

The .NET Compact Framework does not support remoting. See Message Queuing in the .NET Compact Framework for alternative solutions.

Security

Security differences and considerations are described in Security in the .NET Compact Framework.

Serialization

Because of size and performance considerations, the .NET Compact Framework does not support binary serialization using BinaryFormatter, or SOAP serialization using SoapFormatter.

However, the .NET Compact Framework does provide serialization support for transmitting object data by using SOAP in XML Web services, and serializing datasets to XML.

Size

The .NET Compact Framework is 8 percent the size of the full .NET Framework redistributable package. The size on disk is 50 percent smaller because of Windows Embedded CE file system compression.

Sockets

Not all socket options are supported. For more information, see Socket Programming.

String Manipulations, Regular Expressions

Applications that use regular expressions in the .NET Compact Framework are not binary compatible with applications that use regular expressions in the full .NET Framework, but they are source-code compatible.

Threads

A .NET Compact Framework application creates up to four threads:

  • A main application thread.

  • A thread that is used to control various period timers and time-outs that can be scheduled by the system or by applications.

  • A thread that is used to track changes to the active TCP/IP interfaces (simulating the media sense behavior that is present on Windows XP but not on Windows Embedded CE).

  • A thread that is used to run object finalizers. This thread is created when the first finalizable object is garbage-collected.

For more information about threading support, see Threading in the .NET Compact Framework.

Time Intervals

The Now property returns a value that is specific only to seconds, not milliseconds. You can get a finer measurement by using the TickCount property.

Timers

The Start and Stop methods for a System.Timers.Timer object are not supported, but you can start and stop timing by setting the Enabled property of a System.Windows.Forms.Timer object to true or false.

Visual Basic My

The compact supports the Visual Basic My feature (see Development with My), except for the following My objects:

  • My.Application

  • My.Computer

  • My.User

  • My.Settings

Web Services

The Web services client runs assembles that are generated by wsdl.exe directly.

Do not use localhost to create a Web service on the device, because localhost refers to the device that is running the application. Instead, you should use either the machine's name or its IP address.

XML

Because of size considerations, the .NET Compact Framework does not support XML schema validation. It does support the XML Document Object Model (DOM). For more information, see Data Access and XML Support in the .NET Compact Framework.

See Also

Other Resources

Overview of the .NET Compact Framework