web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

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

I have the same question (0)
  • Community Member Profile Picture
    on at

    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?

  • Community Member Profile Picture
    on at

    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();

    }

     

  • Suggested answer
    tw0sh3ds Profile Picture
    5,600 on at

    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

    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.

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans