Problem with my windows service [modified]
-
Hi I am developing an windows service that sends email notifications to all not activated members and not published users. I tested my email notifications with a sample windows application but the same notifications are failing in my service. But I put all of the dlls in the same directory as my service exe file. Here is the piece that fails: SMPTServer = this.gs.SMTPServer; if (userEmail != "" && userEmail != null) { //Send Email Notification doXtop.Framework.Messaging.Message msg = new doXtop.Framework.Messaging.Message(); -- it fails here, but this works with my windows test application. } The service logged with "Object reference not set to an instance of an object." Can any give me ideas, how can I solve this.
modified on Wednesday, March 18, 2009 12:47 PM
-
Hi I am developing an windows service that sends email notifications to all not activated members and not published users. I tested my email notifications with a sample windows application but the same notifications are failing in my service. But I put all of the dlls in the same directory as my service exe file. Here is the piece that fails: SMPTServer = this.gs.SMTPServer; if (userEmail != "" && userEmail != null) { //Send Email Notification doXtop.Framework.Messaging.Message msg = new doXtop.Framework.Messaging.Message(); -- it fails here, but this works with my windows test application. } The service logged with "Object reference not set to an instance of an object." Can any give me ideas, how can I solve this.
modified on Wednesday, March 18, 2009 12:47 PM
You might get the NUll reference because you first check if userEmail = "" It is more wise to create the next IF if (null != userEmail && !userEmail.Equals(String.Empty))
-
You might get the NUll reference because you first check if userEmail = "" It is more wise to create the next IF if (null != userEmail && !userEmail.Equals(String.Empty))
Hi I checked it, it was not problem in the line of code that I posted but its the problem with doXtop.Framework.Messaging.Message msg = new doXtop.Framework.Messaging.Message(); This is strange. For me the following line of code is working but the above one is not working: doXtop.Framework.Messaging.Message.SendEmail("info@doXtop.com", userEmail, subject, message, SMTPServer);
-
Hi I checked it, it was not problem in the line of code that I posted but its the problem with doXtop.Framework.Messaging.Message msg = new doXtop.Framework.Messaging.Message(); This is strange. For me the following line of code is working but the above one is not working: doXtop.Framework.Messaging.Message.SendEmail("info@doXtop.com", userEmail, subject, message, SMTPServer);
can/will you show the code of the messaging class?
-
can/will you show the code of the messaging class?
Here is the code of my messaging class: public class Message : IDisposable { public Hashtable HtEmails; public HttpContext Context; public bool ThreadExecution = false; public string From; public string Subject; public string SmtpClient; public string Body; public string EmailProvider; public string Username; public string FullName; public string ActivationMessage; public Guid UserId; public GlobalSettings gs; public Uri Url; public string ApplicationPath; public enum Box { Inbox, Outbox } DataAccess _da; DataSource _ds; public Message() { _da = new DataAccess(); _ds = new DataSource(_da); ConfigurationProvider cp = new ConfigurationProvider(); gs = cp.GlobalSettings; } public bool InsertMessage(string from, string to, string subject, string body, string senderIPAddress) { try { SqlParameter[] _params = { new SqlParameter("@MessageId", Guid.NewGuid()), new SqlParameter("@From", from), new SqlParameter("@To", to), new SqlParameter("@Subject", subject), new SqlParameter("@Body", body), new SqlParameter("@SenderIPAddress", senderIPAddress) }; _ds.ExecuteNonQueryProcedureProxy("InsertMessage", _params); return true; } catch (Exception e) { EventLog.WriteEntry("WideDocs", e.ToString(), EventLogEntryType.Error); return false; } } }
-
Here is the code of my messaging class: public class Message : IDisposable { public Hashtable HtEmails; public HttpContext Context; public bool ThreadExecution = false; public string From; public string Subject; public string SmtpClient; public string Body; public string EmailProvider; public string Username; public string FullName; public string ActivationMessage; public Guid UserId; public GlobalSettings gs; public Uri Url; public string ApplicationPath; public enum Box { Inbox, Outbox } DataAccess _da; DataSource _ds; public Message() { _da = new DataAccess(); _ds = new DataSource(_da); ConfigurationProvider cp = new ConfigurationProvider(); gs = cp.GlobalSettings; } public bool InsertMessage(string from, string to, string subject, string body, string senderIPAddress) { try { SqlParameter[] _params = { new SqlParameter("@MessageId", Guid.NewGuid()), new SqlParameter("@From", from), new SqlParameter("@To", to), new SqlParameter("@Subject", subject), new SqlParameter("@Body", body), new SqlParameter("@SenderIPAddress", senderIPAddress) }; _ds.ExecuteNonQueryProcedureProxy("InsertMessage", _params); return true; } catch (Exception e) { EventLog.WriteEntry("WideDocs", e.ToString(), EventLogEntryType.Error); return false; } } }
I believe your problem is this: public Hashtable HtEmails; public HttpContext Context; public bool ThreadExecution = false; public string From; public string Subject; public string SmtpClient; public string Body; public string EmailProvider; public string Username; public string FullName; public string ActivationMessage; public Guid UserId; public GlobalSettings gs; public Uri Url; public string ApplicationPath; they are mostly null. Havent you forget the { get; set; } to use them as properties? You do not use any of these publics in your class and you cannot set them from outside.
In Word you can only store 2 bytes. That is why I use Writer.