Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

Cannot delete attachement from draft email !!

Posted on by

Hello, 

i work with CRM dynamics 365, i have an error when i want to delete attachement from email in draft status, also i can't delete the email contains attachement 

i tried to delete the email with c# code in debug and i have the same error 

6761.error.PNG

this is the trace : 

>Crm Exception: Message: An unexpected error occurred., ErrorCode: -2147220970, InnerException: System.NullReferenceException: La référence d'objet n'est pas définie à une instance d'un objet.
   à Microsoft.Crm.ObjectModel.ActivityMimeAttachmentService.DeleteInternal(BusinessEntityMoniker moniker, ExecutionContext context, Boolean updateEmailAttachmentCount)
   à Microsoft.Crm.ObjectModel.ActivityMimeAttachmentService.DeleteAssociatedAMAttachments(BusinessEntityMoniker moniker, Int32 objectTypeCode, ExecutionContext context)
   à Microsoft.Crm.Common.ObjectModel.EmailService.Delete(BusinessEntityMoniker moniker, ExecutionContext context)
[2017-06-13 09:25:24.188] Process: w3wp |Organization:85b57212-bfb8-449a-9050-fb65e7e37bef |Thread:   40 |Category: Platform |User: 51947b1f-4a5d-e611-80c4-d4bed9b10258 |Level: Error |ReqId: 8019d410-9e40-4f27-bcbb-2eb43344e1c0 |ActivityId: 6d31c0de-d4f2-4d7d-a2ee-3666d0c28a03 | MessageProcessor.Execute  ilOffset = 0x218
>MessageProcessor fail to process message 'Delete' for 'email'.
[2017-06-13 09:25:24.188] Process: w3wp |Organization:00000000-0000-0000-0000-000000000000 |Thread:   40 |Category: Platform |User: 00000000-0000-0000-0000-000000000000 |Level: Error |ReqId: 8019d410-9e40-4f27-bcbb-2eb43344e1c0 |ActivityId: 6d31c0de-d4f2-4d7d-a2ee-3666d0c28a03 | ExceptionConverter.ToSingleFaultOther  ilOffset = 0x30
>System.NullReferenceException: Microsoft Dynamics CRM has experienced an error. Reference number for administrators or support: #79C2C5DB: System.NullReferenceException: La référence d'objet n'est pas définie à une instance d'un objet.
   à Microsoft.Crm.ObjectModel.ActivityMimeAttachmentService.DeleteInternal(BusinessEntityMoniker moniker, ExecutionContext context, Boolean updateEmailAttachmentCount)
   à Microsoft.Crm.ObjectModel.ActivityMimeAttachmentService.DeleteAssociatedAMAttachments(BusinessEntityMoniker moniker, Int32 objectTypeCode, ExecutionContext context)
   à Microsoft.Crm.Common.ObjectModel.EmailService.Delete(BusinessEntityMoniker moniker, ExecutionContext context)
[2017-06-13 09:25:42.658] Process: w3wp |Organization:85b57212-bfb8-449a-9050-fb65e7e37bef |Thread:   65 |Category: Platform.Sdk |User: 51947b1f-4a5d-e611-80c4-d4bed9b10258 |Level: Error |ReqId: daefea23-0a66-4cc5-a21b-829a61ceefc2 |ActivityId: daefea23-0a66-4cc5-a21b-829a61ceefc2 | VersionedPluginProxyStepBase.Execute  ilOffset = 0x64
>Web Service Plug-in failed in SdkMessageProcessingStepId: {89CABB1B-EA3E-DB11-86A7-000A3A5473E8}; EntityName: email; Stage: 30; MessageName: Delete; AssemblyName: Microsoft.Crm.Extensibility.InternalOperationPlugin, Microsoft.Crm.ObjectModel, Version=8.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35; ClassName: Microsoft.Crm.Extensibility.InternalOperationPlugin; Exception: Unhandled Exception: System.Reflection.TargetInvocationException: Une exception a été levée par la cible d'un appel.
   à System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
   à System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments)
   à System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   à System.Web.Services.Protocols.LogicalMethodInfo.Invoke(Object target, Object[] values)
   à Microsoft.Crm.Extensibility.InternalOperationPlugin.Execute(IServiceProvider serviceProvider)
   à Microsoft.Crm.Extensibility.V5PluginProxyStep.ExecuteInternal(PipelineExecutionContext context)
   à Microsoft.Crm.Extensibility.VersionedPluginProxyStepBase.Execute(PipelineExecutionContext context)
Inner Exception: System.NullReferenceException: La référence d'objet n'est pas définie à une instance d'un objet.
   à Microsoft.Crm.ObjectModel.ActivityMimeAttachmentService.DeleteInternal(BusinessEntityMoniker moniker, ExecutionContext context, Boolean updateEmailAttachmentCount)
   à Microsoft.Crm.ObjectModel.ActivityMimeAttachmentService.DeleteAssociatedAMAttachments(BusinessEntityMoniker moniker, Int32 objectTypeCode, ExecutionContext context)
   à Microsoft.Crm.Common.ObjectModel.EmailService.Delete(BusinessEntityMoniker moniker, ExecutionContext context)

*This post is locked for comments

  • yosra.walid Profile Picture
    yosra.walid on at
    RE: Cannot delete attachement from draft email !!

    Yes i work with this plugin since Junuary 2017, i think the problem is after to installation of SP1 (dynamics 365)

    this is the code :

     private static void CreateActivityMimeAttachement(IOrganizationService service, EntityReference sourceEmail, string filename, string documentBody)

           {

               Entity ResultEntity = service.Retrieve("email", sourceEmail.Id, new ColumnSet(true));

               Entity ActivityMimeAttachement = new Entity("activitymimeattachment");

               ActivityMimeAttachement["objectid"] = new EntityReference("email", ResultEntity.Id);

               ActivityMimeAttachement["objecttypecode"] = "email";

               ActivityMimeAttachement["filename"] = filename;

               ActivityMimeAttachement["body"] = documentBody;

               ActivityMimeAttachement["mimetype"] = @"application/pdf";

               service.Create(ActivityMimeAttachement);

           }

  • Aiden Kaskela Profile Picture
    Aiden Kaskela 19,692 on at
    RE: Cannot delete attachement from draft email !!

    Can you include the code for CreateActivityMimeAttachement? I've added all the same functionality (minus the PDF part) in Workflow Elements so I can check your code against that.

    Have you verified the pdf is generating correctly on your server?

  • yosra.walid Profile Picture
    yosra.walid on at
    RE: Cannot delete attachement from draft email !!

    Hi the scenario is  : in the opportunity entity i generate a word document and i saved it in the annotation of opportunity

    and i added a Dialogue, in this dialog i choose the document word to add to the  email ( email created in the dialog)  and i convert it to pdf and add it to an email, i use workflow ith CodeActivity

    this a part of my code( it work fine since i passed to crm 2016 to Dynamics 365)

    private static void ConvertToPDFandAttachToEmail(IOrganizationService service, EntityReference email, string filename, string documentBody, Guid guidNote)

           {

               if (!string.IsNullOrEmpty(filename))

               {

                   //Create temporary folder to stock word and pdf doc

                   Guid folderName = Guid.NewGuid();

                   string folderPath = Properties.Settings.Default.UrlTempFolder + folderName.ToString() + "\\";

                   string fileWord = folderPath + filename;

                   bool exists = System.IO.Directory.Exists(folderPath);

                   if (!exists)

                       System.IO.Directory.CreateDirectory(folderPath);

                   string fileNameWithOutExtension = Path.GetFileNameWithoutExtension(fileWord);

                   string fileExtension = Path.GetExtension(fileWord);

                   if (fileExtension.Equals(".doc") || fileExtension.Equals(".docx"))

                   {

                      //download the word doc frm crm and stock it to tomporary folder

                       using (FileStream fileStream = new FileStream(folderPath + filename, FileMode.OpenOrCreate))

                       {

                           byte[] fileContent = Convert.FromBase64String(documentBody);

                           fileStream.Write(fileContent, 0, fileContent.Length);

                           fileStream.Close();

                           //Convert doc word to pdf                  

                           string FileToJoindre = Path.ChangeExtension(folderPath + fileNameWithOutExtension, "pdf");

                         //this is methode call and externe service

                           convertToPDF(fileWord, FileToJoindre);

                           byte[] fileContentPDF = File.ReadAllBytes(FileToJoindre);

                           string fileBodyContent = Convert.ToBase64String(fileContentPDF);

                           string newFileName = Path.GetFileName(FileToJoindre);

                           //Joindre doc to email

                           CreateActivityMimeAttachement(service, email, newFileName, fileBodyContent);

                       }

                   }

                   else

                   {

                       //Create attachement without  convert to pdf if its not a word doc

                       CreateActivityMimeAttachement(service, email, filename, documentBody);

                   }

                   //delete folder contains word and pdf doc

                   Directory.Delete(folderPath, true);

               }

           }

  • Aiden Kaskela Profile Picture
    Aiden Kaskela 19,692 on at
    RE: Cannot delete attachement from draft email !!

    Hi Soy,

    When you say a plugin, are you referring to a Workflow or an actual Plugin? I didn't think there was a message to generate the word templates in the plugins.

    Given you scenario, the most likely cause is the code which is attaching the template to the email. If you have that code, could you share it and I can tell you what might be wrong?

    Thanks,

     Aiden

  • yosra.walid Profile Picture
    yosra.walid on at
    RE: Cannot delete attachement from draft email !!

    Hi thank your for your answer ,

    i work on premise, the attachement included in the email with plugin

    the plugin generate word document and convert to pdf and add it to the email

    Thank your for your help

  • Aiden Kaskela Profile Picture
    Aiden Kaskela 19,692 on at
    RE: Cannot delete attachement from draft email !!

    Hi Soy,

    The null reference exception looks like it's coming from Dynamics itself, not any code you're running (I only see MSFT in the stack trace but may have missed it). Are you on prem or online? How are the attachments being included in your email messages?

    Thanks,

     Aiden

  • yosra.walid Profile Picture
    yosra.walid on at
    RE: Cannot delete attachement from draft email !!

    Thank you

    La référence d'objet n'est pas définie à une instance d'un objet. it means  :Object reference not set to an instance of an object

    But i didn't have any null value

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Cannot delete attachement from draft email !!

    I want to help but can't understand the language @@

    Some null exception: La référence d'objet n'est pas définie à une instance d'un objet.

    Some OOB plugins error: Web Service Plug-in failed in SdkMessageProcessingStepId: {89CABB1B-EA3E-DB11-86A7-000A3A5473E8}; EntityName: email; Stage: 30; MessageName: Delete; AssemblyName: Microsoft.Crm.Extensibility.InternalOperationPlugin

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,235 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans