invalidoperationexception

Python cdecimal InvalidOperation

痞子三分冷 提交于 2019-12-09 16:17:56
问题 I am trying to read financial data and store it. The place I get the financial data from stores the data with incredible precision, however I am only interested in 5 figures after the decimal point. Therefore, I have decided to use t = .quantize(cdecimal.Decimal('.00001'), rounding=cdecimal.ROUND_UP) on the Decimal I create, but I keep getting an InvalidOperation exception. Why is this? >>> import cdecimal >>> c = cdecimal.getcontext() >>> c.prec = 5 >>> s = '45.2091000080109' >>> # s = '0

Modifying Collection when using a foreach loop in c# [duplicate]

主宰稳场 提交于 2019-12-09 03:05:56
问题 This question already has answers here : What is the best way to modify a list in a 'foreach' loop? (11 answers) Closed 6 years ago . Basically, I would like to remove an item from a list whilst inside the foreach loop. I know that this is possible when using a for loop, but for other purposes, I would like to know if this is achievable using a foreach loop. In python we can achieve this by doing the following: a = [1, 2, 3, 4, 5, 6, 7, 8, 9] for i in a: print i if i == 1: a.pop(1) This gives

How can I debug misleading GDI OutOfMemory exceptions?

我怕爱的太早我们不能终老 提交于 2019-12-08 04:03:38
问题 I have a function which resizes a bitmap. It's such a "bread and butter" operation that I simply copied it from another project: private Bitmap ResizeBitmap(Bitmap orig) { Bitmap resized = new Bitmap(this.Xsize, this.Ysize, PixelFormat.Format16bppGrayScale); resized.SetResolution(orig.HorizontalResolution, orig.VerticalResolution); using (Graphics g = Graphics.FromImage(resized)) { g.DrawImage(orig, 0, 0, resized.Width, resized.Height); } return resized; } However, I kept getting OutOfMemory

Why does this error not get caught?

廉价感情. 提交于 2019-12-08 03:30:53
问题 I have the following code in my project, deleteselector is a form that has a datagridview (with autosize columns) on it. try { if (deleteSelector.ShowDialog() == DialogResult.OK) { } } catch (InvalidOperationException) { //Bug workaround } The try catch is because a pop-up form with a gridview on it trows a invalidoperationexception once in a while. This is the suggested workaround, see http://connect.microsoft.com/VisualStudio/feedback/details/145633/invalidoperationexception-thrown-when-a

How can I debug misleading GDI OutOfMemory exceptions?

放肆的年华 提交于 2019-12-06 22:30:28
I have a function which resizes a bitmap. It's such a "bread and butter" operation that I simply copied it from another project: private Bitmap ResizeBitmap(Bitmap orig) { Bitmap resized = new Bitmap(this.Xsize, this.Ysize, PixelFormat.Format16bppGrayScale); resized.SetResolution(orig.HorizontalResolution, orig.VerticalResolution); using (Graphics g = Graphics.FromImage(resized)) { g.DrawImage(orig, 0, 0, resized.Width, resized.Height); } return resized; } However, I kept getting OutOfMemory exceptions on Graphics g = Graphics.FromImage(resized) . I'm aware that, when it comes to GDI,

What is a parent freezable? What does this error mean?

我的未来我决定 提交于 2019-12-06 19:14:12
问题 I'm getting this error: Cannot use a DependencyObject that belongs to a different thread than its parent Freezable What does that even mean? Is it in English? Is the parent frozen, or is it just freezable? Any way to make a parent not freezable, if it makes the error go away? What's happening: I have two opengl winforms controls in a WPF app, and so far, everything's been working smoothly (I think). Now, I've added an update so that when one winform control updates the image, the other should

Why does this error not get caught?

不羁的心 提交于 2019-12-06 06:34:21
I have the following code in my project, deleteselector is a form that has a datagridview (with autosize columns) on it. try { if (deleteSelector.ShowDialog() == DialogResult.OK) { } } catch (InvalidOperationException) { //Bug workaround } The try catch is because a pop-up form with a gridview on it trows a invalidoperationexception once in a while. This is the suggested workaround, see http://connect.microsoft.com/VisualStudio/feedback/details/145633/invalidoperationexception-thrown-when-a-form-with-a-bound-datagridview-with-auto-sizing-columns-is-shown Earlier, I used Show on the

InvalidOperationException with Process

与世无争的帅哥 提交于 2019-12-05 23:25:19
问题 I'm starting a new process using the following code: Process p = new Process(); p.StartInfo.FileName = "..."; p.StartInfo.Arguments = "..."; p.Start(); p.WaitForExit(300000); // 5 minutes if (!p.HasExited) p.Kill(); Console.Write(p.ExitCode); When the process ends within the 5 minutes, that's working, but when it doesn't, I get InvalidOperationException (Process must exit before requested information can be determined...). Any idea why I'm getting this exception? Thank you. 回答1: According to

What is a parent freezable? What does this error mean?

你离开我真会死。 提交于 2019-12-05 01:15:26
I'm getting this error: Cannot use a DependencyObject that belongs to a different thread than its parent Freezable What does that even mean? Is it in English? Is the parent frozen, or is it just freezable? Any way to make a parent not freezable, if it makes the error go away? What's happening: I have two opengl winforms controls in a WPF app, and so far, everything's been working smoothly (I think). Now, I've added an update so that when one winform control updates the image, the other should as well. That actually used to work, and now I'm getting that error. Stepping through the code has the

Why is this code throwing an InvalidOperationException?

感情迁移 提交于 2019-12-04 19:55:30
问题 I think that my code should make the ViewBag.test property equal to "No Match" , but instead it throws an InvalidOperationException . Why is this? string str = "Hello1,Hello,Hello2"; string another = "Hello5"; string retVal = str.Split(",".ToCharArray(), StringSplitOptions.RemoveEmptyEntries) .First(p => p.Equals(another)); if (str == another) { ViewBag.test = "Match"; } else { ViewBag.test = "No Match"; //this does not happen when it should } 回答1: As you can see here, the First method throws