Questions tagged [invalidoperationexception]

The exception that is thrown when a method call is invalid for the object's current state.

The exception that is thrown when a method call is invalid for the object's current state.

More information is available on Docs.

505 questions
261
votes
10 answers

nullable object must have a value

There is paradox in the exception description: Nullable object must have a value (?!) This is the problem: I have a DateTimeExtended class, that has { DateTime? MyDataTime; int? otherdata; } and a…
Dani
  • 14,639
  • 11
  • 62
  • 110
54
votes
2 answers

Is there a Java equivalent of C#'s InvalidOperationException?

I'm converting some C# code to Java and I need to include an exception that is similar to C#'s InvalidOperationException. Does such a thing exist? Also is there a list of equivalent exception types in the two languages? Thanks. I think in my…
James
  • 2,306
  • 1
  • 22
  • 23
53
votes
1 answer

When to use InvalidOperationException or NotSupportedException?

I am implementing a custom collection implementation that can either be readonly or non-readonly; that is, all the methods that change the collection call a function that is the moral equivalent of: private void ThrowIfReadOnly() { if…
30
votes
4 answers

InvalidOperationException - object is currently in use elsewhere - red cross

I have a C# desktop application in which one thread that I create continously gets an image from a source(it's a digital camera actually) and puts it on a panel(panel.Image = img) in the GUI(which must be another thread as it is the code-behind of a…
para
29
votes
6 answers

Unit test MSBuild Custom Task without "Task attempted to log before it was initialized" error

I have written a few MSBuild custom tasks that work well and are use in our CruiseControl.NET build process. I am modifying one, and wish to unit test it by calling the Task's Execute() method. However, if it encounters a line containing…
David White
  • 3,014
  • 1
  • 32
  • 35
29
votes
9 answers

Why can't we change values of a dictionary while enumerating its keys?

class Program { static void Main(string[] args) { var dictionary = new Dictionary() { {"1", 1}, {"2", 2}, {"3", 3} }; foreach (var s in dictionary.Keys) { //…
Vitaliy
  • 8,044
  • 7
  • 38
  • 66
28
votes
4 answers

What is the analog for .Net InvalidOperationException in Python?

What is the analog for .Net InvalidOperationException in Python?
Konstantin Spirin
  • 20,609
  • 15
  • 72
  • 90
27
votes
4 answers

Is there an alternate hashing algorithm to MD5 for FIPS-enabled systems?

Whenever I try to use MD5 on a Windows XP machine that has FIPS enabled, I am getting a System.InvalidOperationException. Is there an alternate algorithm that I should use instead of MD5 on FIPS?
qazwsx
  • 273
  • 1
  • 3
  • 4
23
votes
3 answers

Invalid Operation Exception from C# Process Class

When I use VSTS debugger to see the properties of instance of class Process, many of the properties are marked with InvalidOperationException. Why? Am I doing anything wrong? I am using VSTS 2008 + C# + .Net 2.0 to develop a console…
George2
  • 44,761
  • 110
  • 317
  • 455
22
votes
3 answers

Why would 'this.ContentTemplate.FindName' throw an InvalidOperationException on its own template?

Ok... this has me stumped. I've overridden OnContentTemplateChanged in my UserControl subclass. I'm checking that the value passed in for newContentTemplate does in fact equal this.ContentTemplate (it does) yet when I call this... var textBox =…
Mark A. Donohoe
  • 28,442
  • 25
  • 137
  • 286
17
votes
6 answers

Queue ForEach loop throwing InvalidOperationException

I haven't used Queues to any real degree before, so I might be missing something obvious. I'm trying to iterate through a Queue like this (every frame): foreach (var e in qEnemy) { //enemy AI code } When an enemy dies, the…
keyboardP
  • 68,824
  • 13
  • 156
  • 205
14
votes
2 answers

InvalidOperationException vs. ArgumentException

I know the summaries and descriptions. But what if the ARGUMENT is in an INVALID STATE? I think the ArgumentException is more appropriate because the InvalidOperationException documentation says that the object on what the method is called itself…
timmkrause
  • 3,367
  • 4
  • 32
  • 59
14
votes
4 answers

The query results cannot be enumerated more than once?

I'm using LINQ to SQL to get a search result of a FullTextSearch stored procedure in Sql server 2008. I dragged the procedure from the server explorer to the designer, and got the method created with the appropriate return type and parameters. Now…
Ahmed
  • 11,063
  • 16
  • 55
  • 67
13
votes
3 answers

HttpContext.Current.Request.Form.AllKeys in ASP.NET CORE version

foreach (string key in HttpContext.Current.Request.Form.AllKeys) { string value = HttpContext.Current.Request.Form[key]; } What is the .net core version of the above code? Seems like .net core took out AllKeys and replaced it with Keys instead.…
bbusdriver
  • 1,577
  • 3
  • 26
  • 58
13
votes
2 answers

Why does ControlCollection NOT throw InvalidOperationException?

Following this question Foreach loop for disposing controls skipping iterations it bugged me that iteration was allowed over a changing collection: For example, the following: List items = new List { new TextBox {Text = "A",…
Meirion Hughes
  • 24,994
  • 12
  • 71
  • 122
1
2 3
33 34