locked
Exception calling NetworkInformation::GetHostNames

    Question

  • <tt> I'm seeing problems with calling the GetHostNames() API from a C++ Metro app. I can call the get profiles or get internet connection apis just fine. When I call the GetHostNames API from my button handler, I'm always seeing an exception, "The filename, directory name, or volume label syntax is incorrect."</tt>

    <tt>try {     </tt>

    <tt>  auto hosts = NetworkInformation::GetHostNames();   </tt>

    <tt>}   </tt>

    <tt>catch( Platform::COMException^ e) {     </tt>

    <tt>  StatusBar->Text += e->ToString();   </tt>

    <tt>} </tt>

    <tt>I tried to declared all the networking location and networking capabilities in the APPX manifest as allowed.</tt>

    <tt>Any ideas why this might not be working for me? </tt>

    <tt>Shawn</tt>

    Thursday, December 15, 2011 3:15 AM

Answers

  • What is the computer name for the problematic system? Using an underscore "_" in the computer name will create this condition for me.

     

    I had to rename the system using characters that do not generate a warning when renamed in order to get the sample project to work. No project capabilities are required for this API.

     

    Thanks,

    -David


    Monday, December 19, 2011 11:43 PM
    Moderator

All replies

  • In what context are you calling this?  GetHostNames works for me from a button handler without any capabilities declared:

    void GetHostNamesTest::MainPage::Button_Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e)
    {
    	auto names = NetworkInformation::GetHostNames();
    	if (names->Size > 0)<br/>	{<br/>		hostNameField->Text = names->GetAt(0)->DisplayName;<br/>	}<br/>}
    
    If this doesn't work for you in your real app does it work for you in a minimal test app? 

    --Rob

    Thursday, December 15, 2011 7:14 AM
    Owner
  • Rob,

     

    The simple test program you suggested above also is failing in the same environment using a new project with just the button whose handler that calls GetHostNames(). I removed any extra network driver components that were installed to rule that out as a possible reason, and I'm still seeing that same behavior.

    Thanks for your help



    • Edited by sb123123 Friday, December 16, 2011 12:15 AM update
    Thursday, December 15, 2011 6:43 PM
  • What is the computer name for the problematic system? Using an underscore "_" in the computer name will create this condition for me.

     

    I had to rename the system using characters that do not generate a warning when renamed in order to get the sample project to work. No project capabilities are required for this API.

     

    Thanks,

    -David


    Monday, December 19, 2011 11:43 PM
    Moderator