Base de conocimientosCentro de exámenes
ESEspañol
Elegir idioma13

CKTIS / C#

System.InvalidOperationException: referencia práctica

System.InvalidOperationException: referencia práctica: InvalidOperationException indica una operación no válida en el estado actual del objeto.

Versión: .NET API; verified on .NET 10.0.14

Sintaxis

System.InvalidOperationException /* select a documented member or constructor */

InvalidOperationException indica una operación no válida en el estado actual del objeto.

Lánzala cuando un argumento pueda ser válido pero no lo sean el orden de llamadas o el estado.

Capturarla de forma general puede ocultar un error de protocolo; corrige el estado o la secuencia.

Son fuentes comunes Single o Pop en una colección vacía y reutilizar un objeto ya finalizado.

El programa completo usa realmente System.InvalidOperationException; su stdout esperado exacto es bad state.

Ejemplos

using System;
using System.Buffers;
using System.Collections.Concurrent;
using System.Collections.Frozen;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Text;
using System.Text.Json;
using System.Text.Json.Nodes;
using System.Text.Json.Serialization;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Channels;
using System.Threading.Tasks;
using Number = System.Int32;

try { throw new InvalidOperationException("bad state"); } catch (InvalidOperationException error) { Console.WriteLine(error.Message); }

Resultado

bad state

El programa completo usa realmente `System.InvalidOperationException`; su stdout esperado exacto es `bad state`.

Fuentes