Link to home
Start Free TrialLog in
Avatar of ianinspain
ianinspain

asked on

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

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

Ian

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!!

Etc
.
.



        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


        }
Avatar of AlexFM
AlexFM

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?
Avatar of ianinspain

ASKER

only the output window

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..

Ian
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

this.Invoke............

"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.
hi thanks.. are you saying it isn't important then?

thanks

ian
ASKER CERTIFIED SOLUTION
Avatar of AlexFM
AlexFM

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial