Agent crashes Notes from COM

I have an agent which processes email and I want to call from I have attached the code from the agent and the code from the button click in .net.

Running and debugging the agent from within Notes, the agent works fine. When I try from .net Notes crashes and dumps a 2mb log file.

I can only conclude that either:
1. The code is processed too fast outside of the debugger
2. There is a security issue.

Thanks in advance.
This is the code in .NET.
Dim lcl_session As Domino.NotesSession
Dim lcl_session_database As Domino.NotesDatabase
Dim doc As NotesDocument
Dim html_email_agent As NotesAgent
lcl_session = New Domino.NotesSession()
lcl_session_database = lcl_session.GetDatabase("", "mail\chafford100.nsf")
If lcl_session_database.IsOpen() = False Then
End If
doc = lcl_session_database.CreateDocument
doc.ReplaceItemValue("Form", "Memo")
doc.ReplaceItemValue("PostedDate", Now())
doc.ReplaceItemValue("SendTo", "")
doc.ReplaceItemValue("Subject", "HTML email 1")
doc.ReplaceItemValue("From", "")
doc.ReplaceItemValue("Body", "This is the test subject")
doc.SaveMessageOnSend = True
doc.Save(True, False)
html_email_agent = lcl_session_database.GetAgent("TestAgent1234") 
If IsNothing(html_email_agent) = False Then
    MsgBox("Agent not found")
End If
'This is the agent:
Sub Initialize
	Dim notes_session As notessession
	Dim notes_database As notesdatabase
	Dim existing_document As notesdocument
	Dim mail_subject As Variant
	Dim recipient_address As Variant 
	Dim html_email_body As Variant
	Dim agent As NotesAgent
	Dim mail_document As NotesDocument 
	'Set up the Current Database.
	Set notes_session = New NotesSession 
	Set notes_database = notes_session.currentdatabase
	'Pull up the document that was created prior to this call
	Set agent = notes_session.CurrentAgent
	Set existing_document = notes_database.GetDocumentByID(agent.ParameterDocID)
	'Create a new document. We will mail this.
	Set mail_document = notes_database.CreateDocument
	'Grab the recipients, subject and body from the existing mail.
	recipient_address = existing_document.GetItemValue("SendTo")
	mail_subject = existing_document.GetItemValue("Subject")
	html_email_body = existing_document.GetItemValue("Body")
	mail_document.SaveMessageOnSend = True
	Call mail_document.ReplaceItemValue("Form", "Memo")
	Call mail_document.ReplaceItemValue("PostedDate", Now())
	Call mail_document.ReplaceItemValue("SendTo", recipient_address)
	Call mail_document.ReplaceItemValue("Subject", mail_subject)
	Call mail_document.ReplaceItemValue("Body",html_email_body)
	Call mail_document.ComputeWithForm(True,False)
	'Send the email
	Call mail_document.send(False)
	'Remove the document which we created to pass the data.
	Call existing_document.Remove(True)
End Sub

Open in new window

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Is this on  server or a Notes client.try notes.notessession rather than domino.

ALso R5 is ancient and no longer supported so it may be tough trying to fully debug.


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
chafford100Author Commented:
Spot on with your suggestion.

Actually just to complete the solution there is a need to late bind everything so I changed the .net code to be CreateObject() etc. etc. When I ran the code the agent worked first time.

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Lotus IBM

From novice to tech pro — start learning today.