i keep getting this error message: Object reference not set to an instance of an object.
private static void GetIPInfo(User user)
{
string ipAddress = System.Web.HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"].ToString();
string city = string.Empty;
string region = string.Empty;
string country = string.Empty;
double? latitude = -1.00;
double? longitude = -1.00;
LocationTools.GetLocationFromIP(ipAddress, out city, out region, out country, out latitude, out longitude);
user.IPAddress = user.IPAddress; **//error is pointing here**
}
Do i need to instantiate something?
Would it be something like this to solve the problem?
user.IPAddress new user.IPAddress = user.ipAddress;
It depends on the way you are calling GetIPInfo(User user). It seems that you are passin null as user. Maybe you should write something like
But it is not clear whether User has to be initialized some way, or it is enough to create an empty instance.
Furthermore, I do not understand what you are trying to do with user.IPAddress = user.IPAddress; It is an instruction that does not seem to have any effect at all, unless there is some other code in the setter of IPAddress which causes some collateral effect, but this is something I would avoid.
EDIT after your comment:
If I got it right (but I’m not really sure), maybe this is more similar to what you really need:
private static User GetIPInfo()
{
User user = new User();
Then you can call it and get a new instance of User that you can assign to a variable or use as you like.