NetworkCredential CryptographicException

M

Marcus Michaels

Hi all,

I am using some old code from a 2.0 project in 4.0, trying to communicate
with a SMTP-Server. The code works fine in 2.0.

In 4.0 I receive a CryptographicException (InvalidHandle) when I am trying
to assign the password to the NetworkCredentials. I tried all constructors,
assigning the password to the property directly, but no change.

Underneath please find part of the class and the stack trace.

Imports System.IO
Imports System.Net
Imports System.Net.Mail
Imports System.Net.Mime
Imports HtmlAgilityPack
Imports System.Security

Public Class MailHelper

Property objMail As New MailMessage
Property objSender As MailAddress
Property objTo As MailAddress
Property objCC As MailAddress
Property objBCC As MailAddress
Property objSmtpClient As SmtpClient
Property objSmtpCredentials As NetworkCredential

Property strMapPath As String

Public Sub New(ByVal strServerMapPath As String)

objSender = New MailAddress(GetAppSetting("MessageFromEmail"),
GetAppSetting("MessageFromName"))

objSmtpClient = New SmtpClient(GetAppSetting("SmtpServer"))
objSmtpClient.UseDefaultCredentials = False

Try
Dim x As NetworkCredential = New
System.Net.NetworkCredential("a","b")

objSmtpClient.Credentials = x

Catch ex As Exception

End Try

objMail.From = objSender

strMapPath = strServerMapPath

End Sub

End Class


STACK TRACE:

bei System.Security.SecureString.ProtectMemory()
bei System.Security.SecureString.InitializeSecureString(Char* value,
Int32 length)
bei System.Security.SecureString..ctor(Char* value, Int32 length)
bei
System.Net.UnsafeNclNativeMethods.SecureStringHelper.CreateSecureString(String plainString)
bei System.Net.NetworkCredential..ctor(String userName, String password)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,516
Members
44,991
Latest member
Josephnag

Latest Threads

Top