本文介绍了MAILMESSAGE新()抛出'的句柄无效“的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么这code:

 毫米MAILMESSAGE新= MAILMESSAGE();

抛出此异常:

  System.Security.Cryptography.CryptographicException被抓
消息=句柄无效。来源= mscorlib程序
堆栈跟踪:
   在System.Security.SecureString.ProtectM​​emory()
   在System.Security.SecureString.InitializeSecureString(字符*值的Int32长度)
   在System.Security.SecureString..ctor(字符*值的Int32长度)
   在System.Net.UnsafeNclNativeMethods.SecureStringHelper.CreateSecureString(字符串plainString)
   在System.Net.Configuration.SmtpNetworkElementInternal..ctor(SmtpNetworkElement元)
   在System.Net.Configuration.SmtpSectionInternal..ctor(SmtpSection部分)
   在System.Net.Configuration.SmtpSectionInternal.GetSection()
   在System.Net.Mail.SmtpClient.get_MailConfiguration()
   在System.Net.Mail.MailMessage..ctor()
   在csEmail.GetMailMessage(字符串主题,弦乐htmlbody)在C:\\用户\\格雷格\\我的Dropbox \\实习生文件\\ mobiledesign \\ APP_ code \\ Utilities.cs:364行
的InnerException:

我的web.config

 < SMTP deliveryMethod =从=correctAddress&GT网络;
    <网络主机=smtp.gmail.com的userName =correctAddress密码=correctPasswordenableSsl =真正的端口=587/>
< / SMTP>


解决方案

为什么它抛出呢?可能是因为MS在做一些事情在幕后愚蠢。

IIRC,这SecureString的code实际上使一个互操作调用到ADVAPI32.DLL。

我的本能反应是:


  1. 禁用任何防病毒软件,看看能否解决。


  2. 请确保您可以访问该DLL。


Why does this code:

MailMessage mm = new MailMessage();

Throw this exception:

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:

My Web.config

<smtp deliveryMethod="Network" from="correctAddress">
    <network host="smtp.gmail.com" userName="correctAddress" password="correctPassword" enableSsl="true" port="587"/>
</smtp>
解决方案

Why it throws it? probably because MS is doing something goofy under the covers.

IIRC, that SecureString code actually makes an interop call down to advapi32.dll.

My knee jerk reaction is to:

  1. Disable any antivirus software, and see if that fixes it.

  2. Make sure you have access to that dll.

这篇关于MAILMESSAGE新()抛出'的句柄无效“的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-14 16:49