Cannot implicitly convert to type string to System.Net.Mail.MailAddress

Ogreintel

I am working on an inventory application system that is updating tracking forms, and I recently converted from System.Web.Mail to System.Net.Mail.

However in regards to an exception if-else statement I made that handles when an item transfer fails, I get a:

"Cannot implicitly convert type 'string' to 'System.Net.Mail.MailAddressCollection" error for the following code block:

else //If the Item Transfer Fails
{
   _formToUpdate.WorkFlowStep = "d";
   _formToUpdate.InventoryCertifier_Initials = dbcontext.Custodies.Where(x => x.Custody_eraider == User.Identity.Name.ToLower()
   _formToUpdate.InventoryCertifierInitials_DtTm = DateTime.Now;
   _formToUpdate.IsFormLockedforEditing = true;

//The notification lists are different in both cases.
NotificationEmail.To = dbcontext.Custodies.Where(x => x.Custody_eraider ==
_formToUpdate.TransferFrom_Sign).Single().Custody_Email + ","
 + dbcontext.Custodies.Where(x => x.Custody_eraider == _formToUpdate.TransferTo_Sign).
Single().Custody_Email + "," + dbcontext.Custodies.Where(x => x.Custody_eraider ==
_formToUpdate.Form_Approv_Reject_By).Single().Custody_Email + ","
+ dbContext.Custodies.Where(x => x.Custody_eraider == _formToUpdate.InventoryCertifier_
Initials).Single().Custody_Email;
}

The error just occurs in the portion of the code that starts with NotificationEmail.To = ...

I'm just not too sure how to go about revising that statement properly.

Any help would be greatly appreciated. If I need to provide more detailed info, please let me know. Thanks!

pmcoltrane

The error is telling you that you cannot convert a string to a MailAddressCollection.

In the System.Net.Mail.MailMessage class, the To property is a MailAddressCollection, not a string as it was in System.Web.Mail.MailMessage.

You'll need to add the email address(es) to that collection. The MailAddressCollection has an Add method that looks like it takes a string in the same format as before, so your code should probably look like:

NotificationEmail.To.Add(/* your expression here */);

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Cannot implicitly convert type ('string', 'string') to System.Net.ICredentialsByHost

From Dev

Cannot implicitly convert type 'void' to 'System.Net.CookieContainer'

From Dev

Cannot implicitly convert type 'string' to 'System.Windows.Forms.TextBox'

From Dev

Cannot implicitly convert type 'string' to 'System.Windows.Forms.TextBox'

From Dev

Cannot implicitly convert type 'System.Collections.Generic.List' to 'string'

From Dev

Error Cannot implicitly convert type 'string' to 'System.DateTime' on return

From Dev

Cannot implicitly convert type 'System.Linq.IQueryable<char[]>' to 'string[]'

From Dev

Cannot implicitly convert type string to System.Drawing.Color

From Dev

cannot implicitly convert System.Type to object

From Dev

Cannot implicitly convert type 'string' to 'String'

From Dev

Cannot implicitly convert 'string' to 'System.TypeCode'

From Dev

Cannot implicitly convert type 'string' to 'decimal'

From Dev

cannot implicitly convert type string to char

From Dev

Cannot implicitly convert type delegate to string

From Dev

Cannot implicitly convert type 'Address' to 'String' in setter

From Dev

Unity cannot implicitly convert type "string" to "bool"

From Dev

Cannot implicitly convert type 'string' to 'bool' [If statement]

From Dev

Cannot implicitly convert type Models to string issues

From Dev

Cannot implicitly convert type 'string' to 'integer'

From Dev

Enum cannot implicitly convert type string to enum

From Dev

Cannot implicitly convert type 'System.Version' to 'System.Net.HttpVersion'

From Dev

Cannot implicitly convert type 'string' to 'System.DateTime', convert datatype for a specific column

From Dev

Cannot implicitly convert type 'System.Threading.Tasks.Task<String> to 'string'

From Dev

Cannot implicitly convert type 'System.Collections.Generic.IEnumerable<string> to string

From Dev

Cannot implicitly convert type 'string' to 'System.Web.UI.WebControls.TextBox' Error

From Dev

SignalR error Cannot implicitly convert type 'System.Threading.Tasks.Task<object>' to 'string'

From Dev

Cannot implicitly convert type 'void' to 'System.Collections.Generic.List<string>'

From Dev

Cannot implicitly convert type 'System.Threading.Tasks.Task<object>' to 'string' in SignalR

From Dev

c# Error: Cannot implicitly convert type 'string' to 'System.Windows.Forms.Control' (CS0029)

Related Related

  1. 1

    Cannot implicitly convert type ('string', 'string') to System.Net.ICredentialsByHost

  2. 2

    Cannot implicitly convert type 'void' to 'System.Net.CookieContainer'

  3. 3

    Cannot implicitly convert type 'string' to 'System.Windows.Forms.TextBox'

  4. 4

    Cannot implicitly convert type 'string' to 'System.Windows.Forms.TextBox'

  5. 5

    Cannot implicitly convert type 'System.Collections.Generic.List' to 'string'

  6. 6

    Error Cannot implicitly convert type 'string' to 'System.DateTime' on return

  7. 7

    Cannot implicitly convert type 'System.Linq.IQueryable<char[]>' to 'string[]'

  8. 8

    Cannot implicitly convert type string to System.Drawing.Color

  9. 9

    cannot implicitly convert System.Type to object

  10. 10

    Cannot implicitly convert type 'string' to 'String'

  11. 11

    Cannot implicitly convert 'string' to 'System.TypeCode'

  12. 12

    Cannot implicitly convert type 'string' to 'decimal'

  13. 13

    cannot implicitly convert type string to char

  14. 14

    Cannot implicitly convert type delegate to string

  15. 15

    Cannot implicitly convert type 'Address' to 'String' in setter

  16. 16

    Unity cannot implicitly convert type "string" to "bool"

  17. 17

    Cannot implicitly convert type 'string' to 'bool' [If statement]

  18. 18

    Cannot implicitly convert type Models to string issues

  19. 19

    Cannot implicitly convert type 'string' to 'integer'

  20. 20

    Enum cannot implicitly convert type string to enum

  21. 21

    Cannot implicitly convert type 'System.Version' to 'System.Net.HttpVersion'

  22. 22

    Cannot implicitly convert type 'string' to 'System.DateTime', convert datatype for a specific column

  23. 23

    Cannot implicitly convert type 'System.Threading.Tasks.Task<String> to 'string'

  24. 24

    Cannot implicitly convert type 'System.Collections.Generic.IEnumerable<string> to string

  25. 25

    Cannot implicitly convert type 'string' to 'System.Web.UI.WebControls.TextBox' Error

  26. 26

    SignalR error Cannot implicitly convert type 'System.Threading.Tasks.Task<object>' to 'string'

  27. 27

    Cannot implicitly convert type 'void' to 'System.Collections.Generic.List<string>'

  28. 28

    Cannot implicitly convert type 'System.Threading.Tasks.Task<object>' to 'string' in SignalR

  29. 29

    c# Error: Cannot implicitly convert type 'string' to 'System.Windows.Forms.Control' (CS0029)

HotTag

Archive