Outlook互操作性

当我宣布时,

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

我收到的错误是

无法嵌入“Microsoft.Office.Interop.Outlook.ApplicationClass”。 请改用适用的界面。

类型’Microsoft.Office.Interop.Outlook.ApplicationClass’没有定义构造函数

解决办法是什么?

使用界面:

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

或禁用此程序集的Interop类型的嵌入(引用 – > Microsoft.Office.Interop.Outlook(右键单击) – >属性 – >将’嵌入互操作类型’设置为False)

有关原因的更多信息,请访问: http : //blogs.msdn.com/b/mshneer/archive/2009/12/07/interop-type-xxx-cannot-be-embedded-use-the-applicable- interface-instead.aspx 。

用这个:

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