By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,884 Members | 949 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,884 IT Pros & Developers. It's quick & easy.

Error: "CallbackOnCollectedDelegate was detected"

P: n/a
ebj
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.NativeM ethods+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?

Dec 31 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
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

Jan 3 '06 #2

P: n/a
ebj
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

"[MSFT]" wrote:
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

Jan 3 '06 #3

P: n/a
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

Jan 4 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.