Share via


Writing and Building Managed C# Applications

This topic explains how to create a Microsoft® .NET Micro Framework project in Microsoft Visual Studio® and write a managed C# application.

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

To create a .NET Micro Framework project in Visual Studio, use the following procedure.

  1. On the File menu in Visual Studio, point to New and then click Project. The New Project dialog box appears.
  2. In the Project types tree, expand the Visual C# node if it is not already expanded.
  3. In the expanded node, click Micro Framework.
  4. In the Templates pane, choose one of the four templates: Class Library, Device Emulator, Console Application, or Window Application.
  5. In the Name box near the bottom of the dialog box, type a name for your project.
  6. 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.

Note

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
  • Resources

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

Note

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.

Troubleshooting

  • 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.
    1. Create and build a library called A.
    2. Create library B that references A and build it.
    3. Create program C that references B and build it.
    4. Delete all instances of A from all the bin directories. (A.dll will be located in all of the directories.)
    5. 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.