Writing and Building Managed C# Applications
When you install the .NET Micro Framework SDK, it integrates itself seamlessly into Visual Studio. To write a managed C# application for the .NET Micro Framework, you use the Visual Studio project template provided with the SDK.
Creating a .NET Micro Framework Project in Visual Studio
- On the File menu in Visual Studio, point to New and then click Project. The New Project dialog box appears.
- In the Project types tree, expand the Visual C# node if it is not already expanded.
- In the expanded node, click Micro Framework.
- In the Templates pane, choose one of the four templates: Class Library, Device Emulator, Console Application, or Window Application.
- In the Name box near the bottom of the dialog box, type a name for your project.
- In the Location box, specify the folder that will contain your project, and then click OK.
When Visual Studio creates your project, it makes a file named
MFWindowApplication1.cs. You can write code in this file, rename it to something else, or add your own C# files to it.
Like any project created with Visual Studio, you can configure your .NET Micro Framework project's properties. To do so, right-click your project's name in the Solution Explorer window and then click Properties on the menu that appears.
|Some of the properties listed on these property pages do not apply to .NET Micro Framework projects.|
The framework does not use the following properties from the Application property page:
- Neutral Languages in the Assembly Information Property
The framework also does not use the following properties from the Build property page:
- Allow Unsafe code
- Generate serialization assembly
- Check for arithmetic overflow/underflow (You can access this property by clicking the Advanced button.)
In addition, the framework does not use the following properties from the Debug page:
- Start Browser with URL
- Working Directory
- Use remote machine
- Enable unmanaged code debugging
- Enable SQL Server debugging
- Enable the Visual Studio Hosting process
|You can use the Command line arguments option only with the emulator.|
Writing and Compiling Applications
The process of developing a managed C# application for the .NET Micro Framework is the same as for any other .NET development platform. First you create the classes, methods, and other elements that your program needs. You then compile your program as you normally would, after which you can either run it on the emulator provided with the .NET Micro Framework or install it on your device for testing and debugging.
- Problem: When compiling, I get an error message that says, "Error: Error while resolving symbols: CLR_E_TYPE_UNAVAILABLE"
Description: This error appears when assemblies reference DLLs that don't exist. The following steps provide an example.
- Create and build a library called A.
- Create library B that references A and build it.
- Create program C that references B and build it.
- Delete all instances of A from all the bin directories. (A.dll will be located in all of the directories.)
- Run C and you get the error.
- Fix: Add a direct reference to the assembly in all assemblies and programs that use it.
- Problem: My program crashes repeatedly in a static constructor.
- Description: If you use a static constructor and there is an error in it, the CLR generates an assertion automatically. The logical course of action for most programmers is to reset the device. However when you do, the constructor immediately causes another assertion.
- Fix: Do not use static constructors. They are not yet fully supported by the .NET Micro Framework.