2

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?)

Frito
  • 1,423
  • 1
  • 15
  • 27
Alex
  • 1,060
  • 2
  • 17
  • 35

4 Answers4

3

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

James Cronen
  • 5,715
  • 2
  • 32
  • 52
  • adding a reference to system.net fixed 11 errors but I still have 11 other errors, what other references might I need to add? – Alex Nov 02 '12 at 20:36
  • 1
    Traditionally the errors will tell you whats missing. You could probably edit them into your post for clarity. – KreepN Nov 02 '12 at 20:37
0

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.

Stephen Gilboy
  • 5,572
  • 2
  • 30
  • 36
0

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

Community
  • 1
  • 1
Frito
  • 1,423
  • 1
  • 15
  • 27
  • Thanks for your response, after reading it I think my problem is Windows Phone doesn't have .NET 4 – Alex Nov 02 '12 at 20:54
  • Not a problem. I didn't even think of the references that Tenner walked you through. I guess I do that on auto-pilot at this point. I haven't done any windows phone development but have you tried dropping the sample project back to the 3.5 framework? Looking at the documentation pretty much all of the System.Net stuff you're using is in 3.5 SP1. – Frito Nov 02 '12 at 21:05
  • when trying to change the target framework on the application tab like you described the only option is windows phone os 7.1 – Alex Nov 02 '12 at 21:10
0

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...

Vadorequest
  • 16,593
  • 24
  • 118
  • 215