[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now


“A first chance exception of type 'System.InvalidOperationException' occurred in System.Windows.Forms.dll COM" problem en my COM event in c#

Posted on 2006-06-02
Medium Priority
Last Modified: 2008-01-09
Hi there,

can anyone help? problem doesn't exist in vs2003 only in vs2005 BUT i have half fixed it....

Basically an event arrives in c# from my COM activeX ... when it arrives it appears to be in a different thread... well i think that is what the error msg means.... Hence i wrote a delegate and a method to do the writing for me.

If i put a breakpoint on the Eventhandler before the { , and when it enters ... continue and take off break point it appears not to be in a different thread

If i don't put a breakpoint the good news is i got it working ... it prints the data to the textbox BUT errror msg is still displayed in the output window..

Am i a missing something??

Thanks in advance


public delegate void WriteToLogCallback(string text);  //this is a delegate to do the job

private void myConnection_Data(int hotlink) // is an event that arrives from my COM dll
            Data myData = (Data)myChannel[0].getData();

            txtNum.Invoke(new WriteToLogCallback(this.WriteToLog), new object[]{myData.num});

//txtNum.Text = myData.num;  // This line used to give errro message and not event write to the text box!!


        private void WriteToLog(string text)
            // Set the textbox text.
            txtNum.Text = text; /// Ok it now prints the details to the screen in txtbox but the error msg is still displayed
//A first chance exception of type 'System.InvalidOperationException' occurred in System.Windows.Forms.dll COM

Question by:ianinspain
  • 4
  • 3
LVL 48

Expert Comment

ID: 16818928
I think you need to apply Invoke to form and not to control. If num is not string, convert it to string:

this->Invoke(new WriteToLogCallback(this.WriteToLog), new object[]{myData.num.ToString()});

Where does "first chance exception" message appear? In Output window or you have exception dialog?

Author Comment

ID: 16830808
only the output window


Author Comment

ID: 16830813
it appears as soon as i attempt to write anything to the screen ... in the case before i used the delegate ... it was in the event... but it wouldn't write anything to the screen.... now i use a delegate.. the msg occurs also in the delegate method as soon as i attempt to write to the screen .... but at least this time it actually writes something..

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.


Author Comment

ID: 16830826
heres the actually msg straight from the output window.... it doesn't give me a exception dialog though..

A first chance exception of type 'System.AccessViolationException' occurred in GetRealTime.exe

and now i am doing


LVL 48

Expert Comment

ID: 16830926
"First chance exception" message means: exception was thrown somewhere, but was catched and successfully handled. If this doesn't happen in your code, this can be in some .NET libraries. You can ignore this message.

Author Comment

ID: 16841249
hi thanks.. are you saying it isn't important then?


LVL 48

Accepted Solution

AlexFM earned 2000 total points
ID: 16841300
First chance exception messages in Output window can be ignored.

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Suggested Courses
Course of the Month20 days, 4 hours left to enroll

873 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question