This documentation is archived and is not being maintained.

Type.Missing Field

Represents a missing value in the Type information. This field is read-only.

Namespace:  System
Assembly:  mscorlib (in mscorlib.dll)

Public Shared ReadOnly Missing As Object

Use the Missing field for invocation through reflection to obtain the default value of a parameter. If the Missing field is passed in for a parameter value and there is no default value for that parameter, an ArgumentException is thrown.

The following code example shows the use of the Missing field to invoke a method with its default arguments.

Imports System
Imports System.Reflection

Public Class OptionalArg
    Public Sub MyMethod(ByVal a As Integer, _
        Optional ByVal b As Double = 1.2, _
        Optional ByVal c As Integer = 1)

        Console.WriteLine("a = " & a & " b = " & b & " c = " & c)
    End Sub
End Class

Class Example
    Public Shared Sub Main()
        Dim o As New OptionalArg()
        Dim t As Type
        t = GetType(OptionalArg)

        Dim bf As BindingFlags = _
            BindingFlags.Public Or BindingFlags.Instance Or _
            BindingFlags.InvokeMethod Or BindingFlags.OptionalParamBinding

        t.InvokeMember("MyMethod", bf, Nothing, o, New Object() {10, 55.3, 12})
        t.InvokeMember("MyMethod", bf, Nothing, o, New Object() {10, 1.3, Type.Missing})
        t.InvokeMember("MyMethod", bf, Nothing, o, New Object() {10, Type.Missing, Type.Missing})
    End Sub
End Class

This code produces the following output:

a = 10 b = 55.3 c = 12

a = 10 b = 1.3 c = 1

a = 10 b = 1.2 c = 1

.NET Framework

Supported in: 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.