Alex
Alex

Reputation: 1060

c# namespace name cannot be found

I am trying to make an asynchronous client for Windows Phone using this code http://msdn.microsoft.com/en-us/library/bew39x2a.aspx in Visual Studio 2010 but I get 22 errors for using things like IPHostEntry and BeginConnect although I copied the code exactly. Any ideas?

Thanks

Edit
The three different types of errors I'm getting are below. most of them are the third one with sockets.socket

Error 1 The type or namespace name 'IPHostEntry' could not be found (are you missing a using directive or an assembly reference?)
Error 2 The name 'Dns' does not exist in the current context
Error 3 System.Net.Sockets.Socket' does not contain a definition for 'BeginConnect' and no extension method 'BeginConnect' accepting a first argument of type 'System.Net.Sockets.Socket' could be found (are you missing a using directive or an assembly reference?)

Upvotes: 2

Views: 4788

Answers (4)

Vadorequest
Vadorequest

Reputation: 18079

I encountered the same issue today. I think it's because VS2010 Express WP created my project using 2.0 .NET framework, I don't know why, I want to use 7.8, but I have only choice between 7.0 and 7.1. I can't change .Net framework version for use the 4.0/4.5, I have only one choice and it's windows phone 7.1, I can't choose the version of the framework separately...

Upvotes: 0

Stephen Gilboy
Stephen Gilboy

Reputation: 5835

The code is missing a namespace before it is declaring classes.

    namespace YourNamespace
    {
        // State object for receiving data from remote device.
         public class StateObject { ...

Also you may be missing namespaces for stuff the code is using. Click on the classes that are highlighted with red squigglies and press ctrl + . and it should give suggestions for namespaces.

Upvotes: 0

Frito
Frito

Reputation: 1453

You should check to see if your project is using the correct version of .Net. In .net 4.0 there is both a "client" and "full" version. Typically when you create a new .Net project in Visual Studio the project is created and referencing the "client profile" .net. Honestly, this gets me every time.

You can change this by doing the following (Visual Studio 2010):

  1. Right click the project in Visual Studio Solution Explorer and select "Properties"
  2. Make sure the "Application" tab is selected
  3. View / Change the "Target Framework:" from ".NET Framework _ Client Profile" to ".NET Framework _"
  4. rebuild your project :-)

Here's a good link explaining the difference between the client profile and the full profile: Differences between Microsoft .NET 4.0 full Framework and Client Profile

Upvotes: 0

James Cronen
James Cronen

Reputation: 5763

You may be missing a reference. Verify that the appropriate DLLs have been identified as project references.

Upvotes: 3

Related Questions