invalidoperationexception

getting error - System.InvalidOperationException was unhandled

丶灬走出姿态 提交于 2019-12-04 04:46:35
问题 I have just started to learn windows application development, and we have been given self learn project to develop one windows application. I am trying to create the application to send email. I have created a class MsgSender.cs to handle that. When I call that class from main form I am getting the following error System.InvalidOperationException was unhandled. Error Message--> Cross-thread operation not valid: Control 'pictureBox1' accessed from a thread other than the thread it was created

Thread cannot access the object

社会主义新天地 提交于 2019-12-04 04:39:59
问题 I declared a field: WriteableBitmap colorBitmap; Then I created a simple thread which does something: private void doSomething() { // ... bla bla bla colorBitmap = new WriteableBitmap(/* parameters */); myImage.Source = colorBitmap; // error here:S } In Windows_Loaded event I declared and started a new thread: private void window_Loaded(object sender, RoutedEventArgs e) { Thread th = new Thread(new ThreadStart(doSomething)); th.Start(); } The problem is that I couldn't change myImage's source

Python cdecimal InvalidOperation

感情迁移 提交于 2019-12-04 03:52:00
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.257585003972054' works! >>> t = cdecimal.Decimal(s).quantize(cdecimal.Decimal('.00001'), rounding

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

…衆ロ難τιáo~ 提交于 2019-12-03 23:33:55
class Program { static void Main(string[] args) { var dictionary = new Dictionary<string, int>() { {"1", 1}, {"2", 2}, {"3", 3} }; foreach (var s in dictionary.Keys) { // Throws the "Collection was modified exception..." on the next iteration // What's up with that? dictionary[s] = 1; } } } I completely understand why this exception is thrown when enumerating a list- it seems reasonable to expect that during enumeration, the Structure of the enumerated object does not change. However- does changing a Value of a dictionary changes its Structure ? Specifically, the structure of its keys? I see

Why is this code throwing an InvalidOperationException?

流过昼夜 提交于 2019-12-03 13:08:26
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 } As you can see here , the First method throws an InvalidOperationException when the sequence on which it is called is empty. Since no element of the

When to use InvalidOperationException or NotSupportedException?

跟風遠走 提交于 2019-12-03 08:09:12
问题 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 (this.isReadOnly) throw new SomeException("Cannot modify a readonly collection."); } I am not sure which of NotSupportedException or InvalidOperationException I should use in that case. 回答1: The MSDN only has one bit of guidance on this precise topic, on

Starting and Forgetting an Async task in MVC Action

我的未来我决定 提交于 2019-12-03 07:29:26
I have a standard, non-async action like: [HttpPost] public JsonResult StartGeneratePdf(int id) { PdfGenerator.Current.GenerateAsync(id); return Json(null); } The idea being that I know this PDF generation could take a long time, so I just start the task and return, not caring about the result of the async operation. In a default ASP.Net MVC 4 app this gives me this nice exception: System.InvalidOperationException: An asynchronous operation cannot be started at this time. Asynchronous operations may only be started within an asynchronous handler or module or during certain events in the Page

When to use InvalidOperationException or NotSupportedException?

只愿长相守 提交于 2019-12-02 21:44:20
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 (this.isReadOnly) throw new SomeException("Cannot modify a readonly collection."); } I am not sure which of NotSupportedException or InvalidOperationException I should use in that case. The MSDN only has one bit of guidance on this precise topic, on NotSupportedException : For scenarios where it is sometimes possible for the object to perform the requested

WPF DependencyObject calling thread exception

谁说我不能喝 提交于 2019-12-02 03:16:32
I have the following code which creates a temporary folder and uses a FileSystemWatcher to poll for files added to the folder on the Location property, and add them to a list: Scratchdisk.cs on Pastebin . The idea is to create a Scratchdisk object, and have FFmpeg extract video frames into it, the FileSystemWatcher builds a list of these files as FFmpeg creates them, and the list is presented as a DependencyObject that my UI binds to. I'm binding to the Scratchdisk object like so: <ItemsControl ItemsSource="{Binding Source=ThumbnailScratchdisk, Path=FileList}"> ... </ItemsControl> On actually

Error:A referential integrity constraint violation occurred on db.SaveChanges() in .net?

别说谁变了你拦得住时间么 提交于 2019-12-01 10:43:49
I have a created a WPF application with Entity framework 4.0. When i am trying to insert record in PhoneNumber Table it inserts first record successfully. But, when i loop through some List and try to insert another item into PhoneNumber table it Insert the record but shows error as: InvalidOperationException was handled by user code: The changes to the database were committed successfully, but an error occurred while updating the object context. The ObjectContext might be in an inconsistent state. Inner exception message: A referential integrity constraint violation occurred: The property