[英]new MailMessage() Throws 'The handle is invalid'
为什么这样的代码:
MailMessage mm = new 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>
我相信实例化MailMessage不会从Web.config中读取。 SmtpClient读取在web.config中设置的SMTP。
您可以显示更多代码吗? 也许其余的GetMailMessage方法。
为什么会扔呢? 可能是因为MS在后台进行了一些愚蠢的事情。
IIRC,该SecureString代码实际上是对advapi32.dll的互操作调用。
我的膝盖跳动反应是:
禁用任何防病毒软件,然后查看是否可以解决该问题。
确保您有权访问该dll。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.