2012-03-07 12 views
2

'ハンドルが無効です' 例外新しいはMailMessage()はなぜ、このコードはない

System.Security.Cryptography.CryptographicException was caught 
Message=The handle is invalid. 

Source=mscorlib 
StackTrace: 
    at System.Security.SecureString.ProtectMemory() 
    at System.Security.SecureString.InitializeSecureString(Char* value, Int32 length) 
    at System.Security.SecureString..ctor(Char* value, Int32 length) 
    at System.Net.UnsafeNclNativeMethods.SecureStringHelper.CreateSecureString(String plainString) 
    at System.Net.Configuration.SmtpNetworkElementInternal..ctor(SmtpNetworkElement element) 
    at System.Net.Configuration.SmtpSectionInternal..ctor(SmtpSection section) 
    at System.Net.Configuration.SmtpSectionInternal.GetSection() 
    at System.Net.Mail.SmtpClient.get_MailConfiguration() 
    at System.Net.Mail.MailMessage..ctor() 
    at csEmail.GetMailMessage(String subject, String htmlbody) in c:\Users\Greg\My Dropbox\Intern Files\mobiledesign\App_Code\Utilities.cs:line 364 
InnerException: 

私のWeb.config

<smtp deliveryMethod="Network" from="correctAddress"> 
    <network host="smtp.gmail.com" userName="correctAddress" password="correctPassword" enableSsl="true" port="587"/> 
</smtp> 
+0

あなたのweb.configはsmtpセクションで何を表していますか? – tedski

答えて

0

なぜそれをスローするのですか?おそらくMSがカバーの下で何か馬鹿にしているからです。

IIRC、そのSecureStringコードは実際にadvapi32.dllへのinterop呼び出しを行います。任意のウイルス対策ソフトウェアを無効にし、それはそれを修正するかどうかを確認

  1. 私の膝ジャーク反応がにあります。

  2. そのDLLにアクセスできることを確認してください。

+0

本当の答え 'MSは、カバーの下で何かおかしいことをしている'それは今日魔法のようにうまくいっている。 – Greg

0

私は信じていますMailMessageをインスタンス化すると、Web.configから読み取られません。 SmtpClientは、web.configで設定されたSMTPを読み取ります。

あなたのコードをもっと表示できますか?たぶん残りのGetMailMessageメソッド。

関連する問題