troubleshooting Question

CallbackOnCollectedDelegate was detected

Avatar of mlprosper
mlprosper asked on
.NET ProgrammingC#
2 Comments1 Solution890 ViewsLast Modified:
One of my programmers is trying to write a demo component using a third-party library to process some forms we have in-house.  However, we keep running into an intermittent problem with a "CallbackOnCollectedDelegate was detected" error.  This occurs on the  myFormSet.Write(); method in the third party library.  From my research, this doesn't seem like a component issue, but rather a coding technique issue.  Could anyone shine some light on how to fix this issue?  We've already tried declaring the variables at the class level, but that doesn't work.  Would we also need to initialize the variable at the class level?  Here is the full error:
CallbackOnCollectedDelegate was detected
Message: A callback was made on a garbage collected delegate of type 'PegasusImaging.WinForms.FormDirector1!PegasusImaging.WinForms.FormDirector1.WorkerImports+DesignRunProc::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.

And the code for the method that causes the error:
AWSHelper objAWS = new AWSHelper();
FormDirector.FormDirector myFormDirector = new FormDirector.FormDirector();
FormDirector.FormSetFile myFormSet = new PegasusImaging.WinForms.FormDirector1.FormSetFile(myFormDirector);

	GatherBarCodeInformation(ref _ExamId, ref _StudentId, ref _PageId, ref _DistrictId, _filledImage);
	CreateForm(Convert.ToInt32(_ExamId), Convert.ToInt32(_PageId), ref myFormSet, myScanFix, objImagXView);

		if (myFormSet.FormDefinitions.Count > 0)
			int myFormCount = myFormSet.FormDefinitions.Count;

			for (int i = 0; i < myFormCount; i++)
				FormDirector.FormDefinitionFile myFormDef = (myFormSet.FormDefinitions[i] as FormDirector.FormDefinitionFile);
				if (myFormDef.Name == "")
					myFormDef.Filename = TempFormSetPath + Path.GetFileName(myFormDef.Filename);

					objAWS.WritingASheet(objAWS.UnfilledBucketName, TempFormSetPath + Path.GetFileName(myFormDef.Filename));
					File.Delete(TempFormSetPath + Path.GetFileName(myFormDef.Filename));                                        
				myFormDef = null;

			myFormSet.Filename = TempFormSetPath + Path.GetFileName(myFormSet.Filename);

			objAWS.WritingASheet(objAWS.UnfilledBucketName, TempFormSetPath + Path.GetFileName(myFormSet.Filename));
			objAWS = null;
			File.Delete(TempFormSetPath + Path.GetFileName(myFormSet.Filename));
	myFormSet.FormDefinitions.Add(new PegasusImaging.WinForms.FormDirector1.FormSetFile(myFormDirector).FormDefinitions[0]);
catch (Exception ex)
	ErrorTime = DateTime.Now.ToString("MM/dd/yyyy HH:mm:ss:tt");
	ErrorMessage = "*Error:" + ex.Message;
	myFormSet = null;
	myFormDirector = null;

Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 2 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 2 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros