Click here to Skip to main content
15,867,937 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
hi all
i have one application which calls one function from dll.
that dll invokes one delegate for capturing fingerprint.
but after 4-5 capture i m getting error..
A callback was made on a garbage collected delegate of type 'SOSComp!CG4Essentials.APIWrapper+CG4_CallbackResultImage::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.


SSO is my dll and CallbackResultImage is my delegate.
I have goggled this problem and got some solutions
i made my delegate declaration as static and also initializing it at every call of function. But still getting same error.
please help me...
god bless u all..
thank you..:)
Posted
Updated 15-May-20 0:27am
Comments
Sergey Alexandrovich Kryukov 4-Sep-12 3:14am    
Normally, it should not happen; if a delegate instance is accessible, it cannot be garbage-collected. It may mean that you screw up the delegate mechanism in some really tricky way which I cannot picture right now. So, can you make a complete but very small code sample which could be used to reproduce the problem? It should not use any special hardware. If this is a problem, please show relevant fragments of your code: how you declare delegate type, delegate instance, invoke it, add a handler to the invocation list of the delegate instance.
--SA
MAU787 4-Sep-12 6:00am    
yes i m using fingerprint scanner.
i m declaring delegate as this..
public static APIWrapper.CG4_CallbackResultImage _CallbackResultImageDelegate=null;

then assigning function to delegate in class constructor:
public WrapperClass()
{

_CallbackResultImageDelegate = new APIWrapper.CG4_CallbackResultImage(UserResultFuc);

GC.KeepAlive(_CallbackResultImageDelegate);
}


then calling delegate like this:
nRc = APIWrapper.CG4_M_Capture_RegisterCallbackResultImage(
nHandle,
_CallbackResultImageDelegate,
this
);

then calling the function which will call this delegate from native code
Sergey Alexandrovich Kryukov 4-Sep-12 15:01pm    
Still not enough. And your first line will not compile. Where is the definition of the delegate type? Don't mix up delegate types and instances. Why do you use GC.KeepAlive?
Where is the definition of APIWrapper?
--SA
MAU787 5-Sep-12 0:56am    
i have class file which uses device sdk and it contains all the delegates..
MAU787 5-Sep-12 1:13am    
i got this solution but i dont know where is the mda.config and how to enable it:
http://msdn.microsoft.com/en-us/43yky316(VS.80).aspx

1 solution

 
Share this answer
 
Comments
Dave Kreskowiak 15-May-20 10:06am    
I doubt it's still going to be useful to the OP because he asked this question eight years ago.
martonthenagy 15-May-20 11:47am    
True. Maybe someone else will find it useful. As I found the linked answer today, which was helpful, despite it is 8 years old too.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900