Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in RPA by (5.3k points)

Consider the following code:

using Microsoft.Office.Interop.Outlook; using OutlookApp = Microsoft.Office.Interop.Outlook.Application; namespace OutlookInterop { class Program { static void Main(string[] args) { OutlookApp outlookApp = new OutlookApp(); MailItem mailItem = outlookApp.CreateItem(OlItemType.olMailItem); mailItem.To = "[email protected]"; mailItem.Subject = "Test Email Alert"; mailItem.HTMLBody = "<html><body>Test email body.</body></html>"; mailItem.Display(false); } } }

This code works fine when I run it on Visual Studio, but when I use it in BluePrism, I get the following compiler error:

Page: Send Email Alert c# Stage: Code1 Type: Error Action: Validate Description: Compiler error at line 2: Cannot implicitly convert type 'object' to 'Microsoft.Office.Interop.Outlook.MailItem'. An explicit conversion exists (are you missing a cast?) Repairable: No

I think I have referenced the correct assemblies in BluePrism i.e.:

enter image description here

And then this is the code inside the actual code stage:

OutlookApp outlookApp = new OutlookApp(); MailItem mailItem = outlookApp.CreateItem(OlItemType.olMailItem); //this would be line 2 mailItem.To = "[email protected]"; mailItem.Subject = "Test Email Alert"; mailItem.HTMLBody = "<html><body>Test email body.</body></html>"; mailItem.Display(false);

So, why would that code work on Visual Studio but not in BluePrism? what is this cast that is missing?

1 Answer

0 votes
by (9.5k points)

I can say that i think the difference is because of how office library is imported.check if "Embed Interop Types" property is set to True. This not only embeds the interop types, but also makes methods and properties that would return object return dynamic instead.

Related questions

0 votes
1 answer
0 votes
1 answer
asked Jan 5, 2022 in RPA by dev_sk2311 (45k points)
0 votes
1 answer
0 votes
1 answer
asked Aug 23, 2021 in RPA by dev_sk2311 (45k points)
0 votes
0 answers

Browse Categories

...