Quantcast
Channel: .NET Framework Class Libraries forum
Viewing all articles
Browse latest Browse all 8156

Getting (impossible!) ArgumentNullException from EnsureStrongCryptoSettingsInitialized() in System.Net.Http when sending email

$
0
0

I have a WPF app running on the 4.6.1 framework.

I am trying to send an email. It works perfectly on other PCs, but not two that I am aware of. One is Windows 10 - the other 8.1. Both have 4.6.1 framework installed.

Here is my email-sending code:

var messageContents = "Some Body";
var message = new MailMessage(
                    @"an.email.address@gmail.com","different.address@microsoft.com.au",
                    $"🐞 Fatal errors from AppName",
                    messageContents)
                {
                    From = new MailAddress(@"an.email.address@gmail.com", "A Display Name"),
                    ReplyToList = {@"random@gmail.com"},
                    Sender = new MailAddress(@"an.email.address@gmail.com", "Sender Display"),
                };

var attach = new Attachment(file); // Create  the file attachment for this e-mail message.
message.Attachments.Add(attach); // Add the file attachment to this e-mail message.
var client = new SmtpClient
{
    EnableSsl = true,
    Host = @"smtp.gmail.com",
    Port = 587,
    Credentials = new NetworkCredential(@"an.email.address@gmail.com", @"*AppropriatePassword*"),
};

client.Send(message);

When this executes, in the client.Send method, I get a

Exception thrown: 'System.ArgumentNullException' in mscorlib.dll

Additional information: Value cannot be null.

With the resulting callstack:

     mscorlib.dll!System.Enum.TryParseEnum(System.Type enumType, string value, bool ignoreCase, ref System.Enum.EnumResult parseResult)    Unknown

     mscorlib.dll!System.Enum.Parse(System.Type enumType, string value, bool ignoreCase)    Unknown
     System.dll!System.Net.ServicePointManager.EnsureStrongCryptoSettingsInitialized()    Unknown
     System.dll!System.Net.ServicePointManager.SecurityProtocol.get()    Unknown
     System.dll!System.Net.TlsStream.ProcessAuthentication(System.Net.LazyAsyncResult result)    Unknown
     System.dll!System.Net.TlsStream.Write(byte[] buffer, int offset, int size)    Unknown
     System.dll!System.Net.PooledStream.Write(byte[] buffer, int offset, int size)    Unknown
     System.dll!System.Net.Mail.SmtpConnection.Flush()    Unknown
     System.dll!System.Net.Mail.ReadLinesCommand.Send(System.Net.Mail.SmtpConnection conn)    Unknown
     System.dll!System.Net.Mail.EHelloCommand.Send(System.Net.Mail.SmtpConnection conn, string domain)    Unknown
     System.dll!System.Net.Mail.SmtpConnection.GetConnection(System.Net.ServicePoint servicePoint)    Unknown
     System.dll!System.Net.Mail.SmtpTransport.GetConnection(System.Net.ServicePoint servicePoint)    Unknown
     System.dll!System.Net.Mail.SmtpClient.GetConnection()    Unknown
     System.dll!System.Net.Mail.SmtpClient.Send(System.Net.Mail.MailMessage message)    Unknown
     name.dll!name.FatalExceptionHandler.EmailZipfile(string file) Line 196    C#

According to the documentation on line 690 @ http://referencesource.microsoft.com/#System/net/System/Net/ServicePointManager.cs,3528c78e8b71ece2,references

It should swallow any parse exceptions, including ArgumentNullException.

So - What's going on? What am I looking at? How do I sort this out?



Viewing all articles
Browse latest Browse all 8156

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>