Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9130637
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T07:59:50+00:00 2026-06-17T07:59:50+00:00

[Note: This is similar to Compare string to null – Why does Resharper think

  • 0

[Note: This is similar to Compare string to null – Why does Resharper think this is always false?, but from the source, it appears there is no [NotNull] attribute on MailMessage.From.]

Consider this method:

public void Send(MailMessage mailMessage)
{
    if (mailMessage.From == null)
        mailMessage.From = new MailAddress(Settings.SmtpSettings.From);
    _smtpClient.Send(mailMessage);
}

ReSharper 7.1.1 is warning me that mailMessage.From cannot be null. I’m completely baffled by this.

mailMessage.From is a MailAddress which is a class (not a struct), so I would think it could definitely be null (although I concede it certainly shouldn’t be at the time the message is sent).

Here is an image showing the ReSharper tooltip I’m getting:

ReSharper indicating that mailMessage.From == null is always false

Any explanation why ReSharper 7.1 thinks mailMessage.From cannot be null, or is this a bug?

Update

So the plot thickens…

I wrote a couple tests and got unexpected results.

This test fails:

[Test]
public void FromPropertyOfMailMessageCannotBeNull()
{
    var message = new MailMessage();
    Assert.IsNotNull(message.From);
}

And this one passes:

[Test]
public void FromPropertyOfMailMessageIsNullIfDefaultConstructorIsUsed()
{
    var message = new MailMessage();
    Assert.IsNull(message.From);
}

So, it looks like ReSharper is just plain wrong that MailMessage.From cannot be null.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T07:59:50+00:00Added an answer on June 17, 2026 at 7:59 am

    It is a bug in ReSharper annotations. In .netFramework 4.0 this property has check for null value in it’s setter but non-null value is not gauranted in the default constructor of MailMessage class. I’ve logged an issue for that: http://youtrack.jetbrains.com/issue/RSRP-337152

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Note: This is similar to this question but it is not the same. I
(note this is similar to but not the same as the question I asked
Note this is not a duplicate of this similar but different question ! My
Note: This is similar, but not quite the same as this other question I've
NOTE: this is very very similar to this SO question , but I need
Note: This similar SO question talks about how to build the same class, but
Note: I've asked this question in a similiar format on superuser but it seems
Note: this question has nothing to do with Knockout.js, but it's about the selectedOptions
Note: This question has broadened in scope from previous revisions. I have tried to
Note this question is similar this one except I'm not working with linq-to-sql, so

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.