public class InvalidOperationException : SystemException
Object
Exception
SystemException
InvalidOperationException
mscorlib
BCL
Represents the error that occurs when an operation cannot be performed.
[Note: InvalidOperationException is typically thrown when the state of one or more objects determines whether an operation can be performed.The InvalidOperationException exception should not be thrown for errors caused by invalid arguments. For invalid argument errors, throw ArgumentException or one of its derived types, such as ArgumentNullException or ArgumentOutOfRangeException.
The ldflda CIL instruction throws InvalidOperationException.
]
The following example demonstrates an error that causes a InvalidOperationException exception.
using System; using System.Collections; public class InvalidOpExample { public static void Main() { int[] array = {0,0}; IEnumerator enumerator = array.GetEnumerator(); Console.Write("{0}",enumerator.Current); } }The output is
Unhandled Exception: System.InvalidOperationException: Enumeration has not started. Call MoveNext.
at System.SZArrayEnumerator.get_Current()
at InvalidOpExample.Main()
System Namespace
InvalidOperationException Constructors
InvalidOperationException() Constructor
InvalidOperationException(System.String) Constructor
InvalidOperationException(System.String, System.Exception) Constructor
public InvalidOperationException();
Constructs and initializes a new instance of the InvalidOperationException class.
This constructor initializes the System.InvalidOperationException.Message property of the new instance to a system-supplied message that describes the error, such as "The requested operation cannot be performed." This message takes into account the current system culture.The System.InvalidOperationException.InnerException property is initialized to
null
.
System.InvalidOperationException Class, System Namespace
public InvalidOperationException(string message);
Constructs and initializes a new instance of the InvalidOperationException class.
- message
- A String that describes the error. The content of message is intended to be understood by humans. The caller of this constructor is required to ensure that this string has been localized for the current system culture.
This constructor initializes the System.InvalidOperationException.Message property of the new instance using message. If message isnull
, the System.InvalidOperationException.Message property is initialized to a system-supplied message. The System.InvalidOperationException.InnerException property is initialized tonull
.
System.InvalidOperationException Class, System Namespace
public InvalidOperationException(string message, Exception innerException);
Constructs and initializes a new instance of the InvalidOperationException class.
- message
- A String that describes the error. The content of message is intended to be understood by humans. The caller of this constructor is required to ensure that this string has been localized for the current system culture.
- innerException
- An instance of Exception that is the cause of the current Exception. If innerException is non-null, then the current Exception was raised in a catch block handling innerException .
This constructor initializes the System.InvalidOperationException.Message property of the new instance using message, and the System.InvalidOperationException.InnerException property using innerException. If message isnull
, the System.InvalidOperationException.Message property is initialized to a system-supplied message.[Note: For information on inner exceptions, see System.Exception.InnerException .]
System.InvalidOperationException Class, System Namespace