all groups > dotnet windows forms > february 2005 >
You're in the

dotnet windows forms

group:

Invoke method appears to have an invalid cast causing an assertion


Invoke method appears to have an invalid cast causing an assertion Kentonis
2/28/2005 7:59:05 AM
dotnet windows forms: 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

RE: Invoke method appears to have an invalid cast causing an assertion Kentonis
3/1/2005 10:41:16 AM
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



[quoted text, click to view]
AddThis Social Bookmark Button