Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Outlook interoperability

Tags:

c#

outlook

When i declare ,

Microsoft.Office.Interop.Excel.ApplicationClass excel =
         new Microsoft.Office.Interop.Excel.ApplicationClass();

I receive errors as

'Microsoft.Office.Interop.Outlook.ApplicationClass' cannot be embedded. Use the applicable interface instead.

and

The type 'Microsoft.Office.Interop.Outlook.ApplicationClass' has no constructors defined

What is the solution?

like image 564
Transistor Avatar asked Aug 04 '11 07:08

Transistor


2 Answers

Either use the interface:

Microsoft.Office.Interop.Outlook.Application outlook = new Microsoft.Office.Interop.Outlook.Application() 

or disable embedding of Interop types for this assembly (References -> Microsoft.Office.Interop.Outlook (right click) -> Properties -> Set 'Embed Interop Types' to False)

More info on the why can be found here: http://blogs.msdn.com/b/mshneer/archive/2009/12/07/interop-type-xxx-cannot-be-embedded-use-the-applicable-interface-instead.aspx.

like image 194
Tom Avatar answered Oct 20 '22 00:10

Tom


Use this:

var outlook = new Microsoft.Office.Interop.Outlook.Application();
like image 20
Emond Avatar answered Oct 20 '22 00:10

Emond