Skip to main content

Notifications

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Dynamics CRM 2016 Online Version : Workflow Error

(0) ShareShare
ReportReport
Posted on by

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
    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
    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
    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
    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

Jainam Kothari – Community Spotlight

We are honored to recognize Jainam Kothari as our June 2025 Community…

Congratulations to the May Top 10 Community Leaders!

These are the community rock stars!

Announcing the Engage with the Community forum!

This forum is your space to connect, share, and grow!

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
Mohamed Amine Mahmoudi Profile Picture

Mohamed Amine Mahmoudi 83 Super User 2025 Season 1

#2
Community Member Profile Picture

Community Member 54

#3
dkrishna Profile Picture

dkrishna 6

Featured topics

Product updates

Dynamics 365 release plans