Error: "CallbackOnCollectedDelegate was detected"

G

Guest

I get this error message from time to time in my new app:

"CallbackOnCollectedDelegate was detected
Message: A callback was made on a garbage collected delegate of type
'System.Windows.Forms!System.Windows.Forms.NativeMethods+WndProc::Invoke'.
This may cause application crashes, corruption and data loss. When passing
delegates to unmanaged code, they must be kept alive by the managed
application until it is guaranteed that they will never be called."

The same code was running without any problems under Visual Studio 2005 Beta
2, but after upgrade to Visual Studio 2005 Professional and the final release
of .NET, I get this error.

Sometimes the code runs without any problems!

What can I do to prevent this from happen?
 
M

[MSFT]

Hello,

Such an error may happen when a delegate is marshaled from managed code to
unmanaged code as a function pointer and a callback was put on the function
pointer, but the delegate was collected by GC. Is there same logic in your
code? Have you locate the exact line that the error happened?

Luke
 
G

Guest

Hello and tank’s fore your answer.
That was what my problem was, it occur on different places in my code, where
I change the visibility or enable/disabled controls (textbox or combobox)

After rewriting the code, the problem seems to be solved.

Einar
 
M

[MSFT]

The problem is still unclear here. If you encountet such a problem again,
and rewriting code wouldn't fix it, you may try to delete the related
control from the form, or re-create the whole form to see if it can help.

Luke
 

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