2016-05-24 3 views
-1

私は(COMなし)C#コードでOutlook NEWMAILをオープンしようとしているが、残念ながら、私は次のエラーコードを取得する:C#コードが新しいOutlookメールを自動的に開こうとしています。エラー0x80020006(DISP_E_UNKNOWNNAME)

0x80020006 (DISP_E_UNKNOWNNAME) 

C#のコードはすぐ下にあります。


using System; 
using System.ComponentModel; 
using System.Data; 
using System.Diagnostics; 
using System.Windows.Forms; 
using Erp.Adapters; 
using Erp.UI; 
using Ice.Lib; 
using Ice.Adapters; 
using Ice.Lib.Customization; 
using Ice.Lib.ExtendedProps; 
using Ice.Lib.Framework; 
using Ice.Lib.Searches; 
using Ice.UI.FormFunctions; 
using System.Net.Mail; 
using System.Runtime.InteropServices; 
using System.Reflection; 
using System.Linq; 
using Microsoft.CSharp; 
using System.IO.Compression; 
using System.Reflection; 
using System.Text; 
using System.IO; 

public class Script 
{ 
    // ** Wizard Insert Location - Do Not Remove 'Begin/End Wizard Added Module Level Variables' Comments! ** 
    // Begin Wizard Added Module Level Variables ** 

    // End Wizard Added Module Level Variables ** 

    // Add Custom Module Level Variables Here ** 

    public void InitializeCustomCode() 
    { 
     // ** Wizard Insert Location- Do not delete 'Begin/End Wizard Added Variable Initialization' lines ** 
     // Begin Wizard Added Variable Initialization 


     this.POForm.AfterToolClick += new Ice.Lib.Framework.AfterToolClickEventHandler(this.POForm_AfterToolClick); 
     // End Wizard Added Variable Initialization 

     // Begin Wizard Added Custom Method Calls 

     // End Wizard Added Custom Method Calls 
    } 

    public void DestroyCustomCode() 
    { 
     // ** Wizard Insert Location - Do not delete 'Begin/End Wizard Added Object Disposal' lines ** 
     // Begin Wizard Added Object Disposal 


     this.POForm.AfterToolClick -= new Ice.Lib.Framework.AfterToolClickEventHandler(this.POForm_AfterToolClick); 
     // End Wizard Added Object Disposal 

     // Begin Custom Code Disposal 

     // End Custom Code Disposal 
    } 

private void POForm_AfterToolClick(object sender, Ice.Lib.Framework.AfterToolClickEventArgs args) 
    { 
    if(args.Tool.Key == "EmailFaxTool") 
{ 

Assembly interopAssembly = Assembly.LoadFile(@"C:\Program Files (x86)\Microsoft Visual Studio 10.0\Visual Studio Tools for Office\PIA\Office14\Microsoft.Office.Interop.Outlook.dll"); 

object outlookApplication = interopAssembly.CreateInstance("Microsoft.Office.Interop.Outlook.ApplicationClass"); 
Type outlookApplicationType = interopAssembly.GetType("Microsoft.Office.Interop.Outlook.ApplicationClass"); 



dynamic mailItem = outlookApplicationType.InvokeMember("CreateItem", BindingFlags.InvokeMethod | BindingFlags.Instance | BindingFlags.Public, null, outlookApplication, new object[] { 0 }); 


//ADDRESS 
//object recipients = outlookApplication.GetType().InvokeMember("Recipients",BindingFlags.GetProperty, null, outlookApplication, null); 
//string To = "[email protected]"; 
//object[] address = new object[1]; 
//address[0] = To; 

//SUBJECT1 
//recipients.GetType().InvokeMember ("Add", BindingFlags.InvokeMethod,null, recipients, address); 
//string subject = "Mail Message Subject"; 
//parms [0] = subject; 

//SUBJECT 
//outlookApplication.GetType().InvokeMember("Subject", BindingFlags.SetProperty,null, outlookApplication, new object[] { 0 }); 
//string msg = "Just a message saying hello"; 


//BODY 
//outlookApplication.GetType().InvokeMember("Body", BindingFlags.SetProperty,null, outlookApplication, new object[] { 0 }); 

//DISPLAY OR SEND 
// Invoke the Send method of the mail item. 
outlookApplication.GetType().InvokeMember("Display", BindingFlags.InvokeMethod,null, outlookApplication,new object[] { true }); 


{ 
throw new Exception("OK."); 
} 
} 

} 
} 
+2

このエラーをGoogleに報告しましたか?多くの情報があるようです。 – BugFinder

+0

Outlookのアプリケーションインターフェイスのメンバーは、[こちらのドキュメント]です(https://msdn.microsoft.com/en-us/library/microsoft)。 office.interop.outlook.application_members.aspx)。表示できるように、Display()メソッドはありません。したがって、 "不明な名前"のランタイムエラーが発生します。これらは* dynamic *キーワードを使用するときに実行する問題の一種です。 Outlookに参照を追加して最初にコードを書くと、間違ったことをコンパイラが伝えることができます。 –

答えて

0

コールMailItem.Display。 Aopplication.Displayメソッドが存在しません。 @Hans Passantがコメントで言及しているように、「動的」を使用するのはかなり恐ろしい考えです。

関連する問題