Represents an exception that is thrown when a method is invoked and, due to the current state of the object involved, the invocation is invalid.
Object
Exception
SystemException
InvalidOperationException
[Visual Basic] Public Class InvalidOperationException Inherits SystemException [C#] public class InvalidOperationException : SystemException [C++] public __gc class InvalidOperationException : public SystemException [JScript] public class InvalidOperationException extends SystemException
The InvalidOperationException is the exception class that is thrown when it denotes an object is in a state that mades calling a method illegal.
An InvalidOperationException should be used when an invocation fails and the failure was not caused by invalid arguments. For example, since DictionaryEnumerator.GetNext() is not a valid method it will throw an InvalidOperationException if the underlying set of objects is modified subsequent to the creation of the enumerator, and GetString throws an InvalidOperationException if the resource set has been closed.
On the other hand, if the invocation fails due to invalid arguments, then ArgumentException or one of its subclasses, ArgumentNullException or ArgumentOutOfRangeException, should be thrown.
Namespace: System
Assembly: mscorlib.dll