Why do I get errors when I open a component in design mode?

Often, when you get an error opening a component in design mode, it's because Visual Studio instantiates the object you are designing. If you have code in the constructor of your class that is referencing objects that are not available at design time, you will get an error.

To avoid this error, you can bracket your constructor code with a call to the MM .NET static method mmAppBase.IsRunning method. If your application is not currently running, this static method returns false.


Note: Although .NET controls have a DesignMode property that indicates if the component is currently in design mode, it isn't set properly during a component's constructor!


For example, in C#:

using OakLeaf.MM.Main;	// Use namespace at the top of your source code file

public class MyClass
{
	public MyClass()
	{
		if (mmAppBase.IsRunning)
		{
			// Code to be executed only at run time
		}
	}
}

In VB .NET:

Imports OakLeaf.MM.Main	' Import namespace at the top of your source code file

Public Class MyClass
   
   	Public Sub New()
      		If mmAppBase.IsRunning Then
			' Code to be executed only at run time
      		End If
   	End Sub
 
End Class

© (c) 2026 Oak Leaf Enterprises, Inc., 1996-2026 • Updated: 09/17/05
Comment or report problem with topic