locked
Code will not compile as expected

    Question

  • Hi,

    I have taken the below c# code from a MS tutorial and converted it into vb.net but it will not compile in vb.net like it does in c#.  I get the below error on HostName.

    'HostName' is not a member of 'Windows.Networking.Proximity.PeerInformation'.

    Here is the MS tutorial for reference -

    https://msdn.microsoft.com/en-us/library/windows/apps/jj207007(v=vs.105).aspx

    What am I missing here?

          PeerInformation selectedDevice = pairedDevices[0];
          // Attempt a connection
          StreamSocket socket = new StreamSocket();
          await socket.ConnectAsync(selectedDevice.HostName,"1");

    Dim selectedDevice As PeerInformation = pairedDevices(0)
    ' Attempt a connection
    Dim socket As New StreamSocket()
    Await socket.ConnectAsync(selectedDevice.HostName, "1")


    • Edited by Ireland75 Monday, April 13, 2015 3:02 PM
    Monday, April 13, 2015 3:02 PM

Answers

  • This is happening because the "HostName" property is part of the Windows Phone Silverlight API. This isn't available in the Windows 8.1 Runtime API.

    Abdulwahab Suleiman

    • Marked as answer by Ireland75 Sunday, April 19, 2015 10:10 AM
    Monday, April 13, 2015 8:47 PM
    Moderator
  • If working on Windows 8.1 Runtime, then you need to only use the available properties in the PeerInformation  class. For example, you can't use "HostName" because it's not available.

    In your code, you can determine the available properties with the help of intellesense when you type "selectedDevice.". Notice the "dot" after "selectedDevice".

    Hope this helps clarify things.


    Abdulwahab Suleiman

    • Marked as answer by Ireland75 Sunday, April 19, 2015 10:11 AM
    Friday, April 17, 2015 8:48 PM
    Moderator
  • If you're writing a Windows Runtime app instead of a Windows Phone Silverlight app you should follow the Windows Runtime documentation. See Proximity and tapping. Using the right docs for the platform will work better, and the Proximity and tapping docs include VB snippets.
    • Marked as answer by Ireland75 Sunday, April 19, 2015 10:10 AM
    Friday, April 17, 2015 9:02 PM
    Owner

All replies

  • This is happening because the "HostName" property is part of the Windows Phone Silverlight API. This isn't available in the Windows 8.1 Runtime API.

    Abdulwahab Suleiman

    • Marked as answer by Ireland75 Sunday, April 19, 2015 10:10 AM
    Monday, April 13, 2015 8:47 PM
    Moderator
  • Hi Abdulwahab,

    Thanks for that pointer...I am indeed building a windows tablet app rather than windows phone app.

    Do you have any idea what code I could change here to get it to compile on a tablet?

    Thanks for your help.

    Kieran

    Tuesday, April 14, 2015 8:54 AM
  • If working on Windows 8.1 Runtime, then you need to only use the available properties in the PeerInformation  class. For example, you can't use "HostName" because it's not available.

    In your code, you can determine the available properties with the help of intellesense when you type "selectedDevice.". Notice the "dot" after "selectedDevice".

    Hope this helps clarify things.


    Abdulwahab Suleiman

    • Marked as answer by Ireland75 Sunday, April 19, 2015 10:11 AM
    Friday, April 17, 2015 8:48 PM
    Moderator
  • If you're writing a Windows Runtime app instead of a Windows Phone Silverlight app you should follow the Windows Runtime documentation. See Proximity and tapping. Using the right docs for the platform will work better, and the Proximity and tapping docs include VB snippets.
    • Marked as answer by Ireland75 Sunday, April 19, 2015 10:10 AM
    Friday, April 17, 2015 9:02 PM
    Owner