Invoke method appears to have an invalid cast causing an assertion

G

Guest

I have the following invocation in my application:

private delegate void InitializeDataDelegate();

/// <summary>Loads information from the database.</summary>
public void InitializeData()
{
if(InvokeRequired)
{
Invoke(new InitializeDataDelegate(this.InitializeData));
}
else
{
blah...blah...blah
}
}

Sometimes, this asserts as so:

EventMananager Callback.
Message: Specified cast is not valid.

Stack Trace: at System.Windows.Forms.Control.MarshaledInvoke( Control
caller, Delegate method, Object[] args, Boolean synchronous)
at System.Windows.Forms.Control.Invoke(Delegate method, Object[] args)
at System.Windows.Forms.Control.Invoke(Delegate method)
at XXXX.XXX.XXX.MyBaseForm.InitializeData() in c:\myfile.cs, line xxx
....
at EventManager.EventHandlerThread() ...

I am not sure what cast is invalid as I have no parameters in my Invoke
call. Could it be the delegate method itself? The documentation says I
could call Invoke with the object args as null, but that seems to me to be
the same thing as not passing a second parameter at all. This happens very
infrequently so I have not been able to repeat the process and find out what
is happening.

Can anyone shed some light on this for me?

Thanks,

Ken
 
G

Guest

I have found the problem. Once I was able to repeat the problem, I was able
to set a break and found that the assertion is misleading. There was nothing
wrong with the invoke. There was a problem further down the line, several
methods away that was doing the invalid cast.

Still, I don't quite understand why the assertion could not display this.

/ken
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top