Link to home
Start Free TrialLog in
Avatar of CipherIS
CipherISFlag for United States of America

asked on

C# 2008 (3.5 Framework) An object reference is required for the non-static field, method, or property

I am receiving the above error.  I've indicated where the error is occurring.  

Public class Sender
{
        SendEmail _sendEmail = new SendEmail();
        .....

	public static void Send(ConfigEmail email)
	{
		email.body = ReplaceCode(email.body, ReplaceType.Html);
		email.body = css.Replace("{MESSAGE EMAIL}", email.body);
		email.body = email.body.ToString().Replace("\r\n", "<br/>");
		email.body = email.body.ToString().Replace("Do not reply to this automatic message", String.Empty);
		try
		{
			_sendEmail.Send(email);  //ERROR OCCURS HERE
		}
		catch (Exception ex)
		{
			throw new Exception(ex.Message);
		}
	}
}

public class SendEmail
{
	public static void Send(ConfigEmail email)
	{
		email.body = ReplaceCode(email.body, ReplaceType.Html);
		email.body = css.Replace("{MESSAGE EMAIL}", email.body);
		email.body = email.body.ToString().Replace("\r\n", "<br/>");
		email.body = email.body.ToString().Replace("Do not reply to this automatic message", String.Empty);
		try
		{
			_sendEmail.Send(email);
		}
		catch (Exception ex)
		{
			throw new Exception(ex.Message);
		}
	}
	
	public class SendEmail
	{
		public static void Send(ConfigEmail emailStruct)
		{
			//........
			SendIt(emailStruct);
		}
		
        private static void SendIt(ConfigEmail emailStruct)
        {
			//.........
			//SMTP Sending email
		}
	}	
}

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of zephyr_hex (Megan)
zephyr_hex (Megan)
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Avatar of Fernando Soto
Fernando Soto
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of CipherIS

ASKER

Yes, figured that out.  Thanks.