'System.Void' can only be used in a GetType expression

An expression in an assignment statement or a declaration uses Void as the type of a variable, procedure parameter, function return, or type argument.

The Void structure is a specialized type used internally by the .NET Framework and particularly by Visual C# and Visual C++. It represents a return value type for a method that does not return a value. Visual Basic uses a Sub procedure when a value is not returned and a Function procedure when a value is returned.

You can test a reference variable with the GetType Operator operator to see if its run-time type is Void, but you cannot use Void in any other context.

Error ID: BC31422

To correct this error

  1. If you want to compare the run-time type of a variable to Void, use the GetType operator.

  2. Unless you have a particular reason to compare a run-time type to Void, remove the reference to it altogether.

See Also

Reference

Void

GetType Operator