Click here to Skip to main content
15,886,137 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hi to All,

I need to Track the IP Address of computer that is connected to a proxy server. I am facing an error. I have code stated below.

using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Web.ClientServices.Providers;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Net;
using System.Net.NetworkInformation;
using System.Net.Sockets;
public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
{
 private StringCollection GetIPs()
    {
        dynamic localIP = new StringCollection();
        dynamic localHostName = Dns.GetHostName();
        dynamic hostEntry = Dns.GetHostEntry(localHostName);
        // Grab all ip addesses.
        foreach (System.Net.IPAddress ipAddr in hostEntry.AddressList)
        {
            localIP.Add(ipAddr.ToString());
        }
        return localIP;
    }
}


}


Error is

Error 42 The type or namespace name 'dynamic' could not be found (are you missing a using directive or an assembly reference?)   
C:\Documents and Settings\Amul\Desktop\AJAXAMULabcd\STARTPAGE.aspx.cs  40  9   C:\...\AJAXAMULabcd\


Kindly Suggest.
Regards,
Amul V V Wayangankar
Posted
Updated 26-Apr-11 6:06am
v4
Comments
HimanshuJoshi 26-Apr-11 12:06pm    
Added pre tags around code and error to highlight them better.
Amul V V Wayangankar 26-Apr-11 12:11pm    
Thanks HimanshuJoshi and do u have any clue regarding this error

What is the .Net version you are targeting? dynamic was introduced with C# 2010.

Update: You cannot use dynamic right away then. Also, you simply do not need to use dynamic in the code you have posted.
 
Share this answer
 
v2
Comments
Amul V V Wayangankar 26-Apr-11 12:19pm    
I am using .Net 2008 IDE. C#3.5
dan!sh 26-Apr-11 23:33pm    
Updated the reply.
"dynamic" is defined as contextual keyword in C# 4.0. If you are using C# 3.0, then you can't use dynamic unless you define it to be something. See more info here[^].
 
Share this answer
 
Comments
Amul V V Wayangankar 26-Apr-11 12:24pm    
What namespace should I import than or is there any alternative way
HimanshuJoshi 26-Apr-11 12:36pm    
Maybe you can use the types that are returned from the methods that are used to assign the values to your dynamic types. I mean use StringCollection for localIP, use String for localHostName and use IPHostEntry for hostEntry.
Amul V V Wayangankar 26-Apr-11 12:40pm    
okay i will try Thanks

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900