About System.InvalidOperationException exception

What is InvalidOperationException

Invalid operation exception. When the method call is invalid for the current state of the object was thrown.

inherit

InvalidOperationException

Detailed description

If the method call failure is caused by reasons other than invalid parameter , then use the exception. Typically, when the state of the object does not support the method call throws this exception. For example, the following method throws an exception or reason nvalidOperationException :

  • IEnumerator.MoveNext If modify a collection of objects created after the enumerator.

  • ResourceSet.GetString If you turn off the set of resources prior to execution method call.

  • XContainer.Add objects If you want to add structure will lead to an incorrect XML document.

  • The method of operating the UI thread attempts non-main thread or threads of the UI.

  • Updating UI thread from a non-UI thread
  • Change the collection when iterating through the collection
  • Its object can not be compared sort of array or collection
  • Will be null <T> is converted to its base type
  • Call system.exception empty collection method
  • No element of a sequence of calls SingleOrDefault or enumeration.
  • Dynamic field access across application domains
Since InvalidOperationException exception may be initiated in many cases, so read exception message returned by the message property is very important.

HRESULT

InvalidOperationException using COR_E_INVALIDOPERATION value of HRESULT 0x80131509.

Guess you like

Origin www.cnblogs.com/yilang/p/12059064.html