Hi
I am getting error here - Attachment is not null here - message.Attachments.Add((System.Net.Mail.Attachment)attachment);
C#
SAPbobsCOM.Attachment attachment = new SAPbobsCOM.Attachment();
attachment.FileName = @"10.0.1.30\SAP_Attachments\Outgoing Payments_204673_20250314_205951");
message.Attachments.Add((System.Net.Mail.Attachment)attachment);Thanks

Emily FosterRank #3,495 · 415 reputationPosted Mar 17, 2025, 2:02 AM EDT
The error you are encountering - "Attachment is not null here" - typically occurs when there is a mismatch between the attachment types being handled.
In your provided code snippet, you are trying to add an attachment of type `SAPbobsCOM.Attachment` to an email message, which expects `System.Net.Mail.Attachment`.
To rectify this issue, you need to convert the `SAPbobsCOM.Attachment` to `System.Net.Mail.Attachment` before adding it to the email message. Here's how you can achieve this:
// Create a System.Net.Mail.Attachment by passing the file path of the SAPbobsCOM.Attachment System.Net.Mail.Attachment attachment = new System.Net.Mail.Attachment(@"10.0.1.30\SAP_Attachments\Outgoing Payments_204673_20250314_205951"); // Add the attachment to the email message message.Attachments.Add(attachment);By making this adjustment, you ensure that the attachment added to the email message is of the correct type, resolving the "Attachment is not null here" error.
If you need further assistance or clarification, feel free to ask.