Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

Dynamics CRM 2016 Online Version : Workflow Error

Posted on by Microsoft Employee

Hello,

I have written a custom workflow activity that references Microsoft.Office.Interop.Excel library. Since we are on Online 2016 version and I have to register the workflow in Sandbox mode, I have used ILMerge to merge my custom workflow library with Microsoft.Office.Interop.Excel library and registered using plugin registration tool. But the workflow fails to execute by throwing following error during runtime :

Unexpected exception from plug-in (Execute): MyCompany.Workflows.FormData: System.TypeLoadException: Could not load type 'Microsoft.Office.Interop.Excel._Application' from assembly 'MyCompany.Workflows.Merged, Version=1.0.0.0, Culture=neutral, PublicKeyToken=9ecbe5344ab2614e'. The type is marked as eligible for type equivalence, but the containing assembly is not loaded as fully trusted.

 

Note : I have used a .snk file to sign the merged assembly during ILmerge. This is the command i used to merge the dlls :

ilmerge /keyfile:MyWorkflows.snk /target:library /copyattrs /targetplatform:v4 /out:MyCompany.Workflows.Merged.dll MyCompany.Workflows.dll  Microsoft.Office.Interop.Excel.dll /allowdup

Any suggestion would be very helpful. Thanks in advance for your time.

Regards,

Pradeep

 

 

 

*This post is locked for comments

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Dynamics CRM 2016 Online Version : Workflow Error

    Hello Pawel, Thanks for your suggestion. To answer your questions :

    1) I think I am using the library correctly.

    2) I am closing the MemoryStream only after disposing ExcelPackage

    3) I dont have an on-premise  environment to test the code

    With some small changes to code am down to this error :

    Unexpected exception from plug-in (Execute): MyCompany.Workflows.FormData: System.Collections.Generic.KeyNotFoundException: The given key was not present in the dictionary.

  • Suggested answer
    tw0sh3ds Profile Picture
    tw0sh3ds 5,600 on at
    RE: Dynamics CRM 2016 Online Version : Workflow Error

    Hi,

    I don't know this library, but are you sure you are using it right? Maybe you should not be closing MemoryStream before disposing this ExcelPackage object?

    Also for you initial question - Interop libraries require MS Office installed on the machine they are running - I guess you cannot assume that in CRM Online there is office installed on the same machine that your plugin runs.

    Have you checked this code without sandbox? Just to exclude situations that this is caused by Online sandbox.

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Dynamics CRM 2016 Online Version : Workflow Error

    Update : I used Epplus.dll and trust issue is gone. But i now have a new issue on hand. Workflow throws following error :

    Unhandled Exception: Microsoft.Crm.CrmException: Unexpected exception from plug-in (Execute): MyCompany.Workflows.FormData: System.Runtime.InteropServices.ExternalException: A generic error occurred in GDI+.

    at Microsoft.Crm.Sandbox.SandboxCodeUnit.Execute(IExecutionContext context)

     

    My code looks like this. What am I doing wrong?

     

    using (ExcelPackage excelPackage = new ExcelPackage())
    {

    ....<Do_Some_Excel_Creation_Logic>...

    MemoryStream ms = new MemoryStream();
    excelPackage.SaveAs(ms);

    byte[] bytes = ms.ToArray();

    var encodedData = Convert.ToBase64String(bytes);

    Entity _EmailAttachment = new Entity("activitymimeattachment");

    ..<Some_Other_Code_Related_To__EmailAttachment >....

     _EmailAttachment["body"] = encodedData;

     _EmailAttachment["mimetype"] = @"application\ms-excel";

    ms.Dispose();
    ms.Close();

    }

     

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Dynamics CRM 2016 Online Version : Workflow Error

    Thanks Guido. Using Microsoft.Office.Interop.Excel.dll I am trying to create a new xls/xlsx file with some values from Case record and then attaching it to a email record and send it. Do you happen to know of any other libraries that do the same task without need of full trust?

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