c# - Visual Studio not Recognising IDisposable Type -
i have following email class contains 1 method send:
using system.net; using system.net.mail; static class email { const string emailaddress = "joebloggs@domain.com"; const string subject = "error detected in application"; public static void send(string body) { using (var client = new smtpclient("mail.mailserevrname.com", 25) { credentials = new networkcredential(), enablessl = false }) { client.send(emailaddress, emailaddress, subject, body); } } } i have used code in multiple applications , have never had problem (no errors, email gets sent as/when expected).
however, in current project, when copy class in, seeing error:
'smtpclient': type used in using statement must implicitly convertible 'system.idisposable'
i have never seen error being produced above code. can see the documentation smtpclient implement idisposable:
public class smtpclient : idisposable
does know why error appearing , not in other applications? or know starting point investigate this?
as @j.steen's comment pointed out, in .net framework 3.5, smtpclient not implement idisposable.
as result, solution create class inherits smtpclient , implements idisposable , use in using.
edit:
class mailer: smtpclient, idisposable { //... } is way implement idisposable , inherit smtpclient
Comments
Post a Comment