netcmd.exe errors out on fresh image of IoT Core

243 Views Asked by At

DragonBoard 410c

Windows 10 IoT Core v.10.0.16273.1000

I SSH into the machine and run netcmd /? which results in this error:

Unhandled Exception: System.IO.FileLoadException: Could not load file or assembly 'System.Runtime, Version=4.0.21.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

That's straight "out of the box."

I realize that this is an insider preview, but that should work, no? I need to connect to enterprise wifi, and this tool is the only way I know to do that.

Is there a quick way to fix that that does not involve waiting for a new build?

Thank you!

2

There are 2 best solutions below

5
On

NETCMD appears to be broken in 10.0.16xxx (at least up to 16299).

From Microsoft.

I've resorted to using code similar to the WiFiConnect sample.

In BackgroundTask Timer:

if (!(wifi.IsConnected("WIRELESS_SSID")))
{
   await wifi.WiFiReconnect();
}

In my WiFi.cs:

public async Task InitWiFi()
{
    // Request access to WiFiAdapter
    WiFiAccessStatus access = await WiFiAdapter.RequestAccessAsync();

    var result = await DeviceInformation.FindAllAsync(WiFiAdapter.GetDeviceSelector()).AsTask();
    if (result.Count >= 1)
    {
         firstAdapter = await WiFiAdapter.FromIdAsync(result[0].Id);

         await firstAdapter.ScanAsync();
         ssid= firstAdapter.NetworkReport.AvailableNetworks.Where(y => y.Ssid == "YOUR_SSID").FirstOrDefault();
    }

}

public bool IsConnected(string network)
{
    string profileName = GetCurrentWifiNetwork();
    if (!String.IsNullOrEmpty(profileName) && (network == profileName))
    {
        return true;
    }
    return false;
}

public async Task<Boolean> WiFiReconnect()
{
      Task<WiFiConnectionResult> didConnect = null;
      WiFiConnectionResult result = null;
      WiFiReconnectionKind autoConnect = WiFiReconnectionKind.Automatic;
      var credential = new PasswordCredential("DOMAIN", USERNAME, "PASSWORD");
      didConnect = firstAdapter.ConnectAsync(ssid, autoConnect, credential).AsTask();
      result = await didConnect;
      if (result.ConnectionStatus == WiFiConnectionStatus.Success)
      {
           return true;
      }
      else
      {
           return false;
      }
 }

private string GetCurrentWifiNetwork()
{
      var connectionProfiles = NetworkInformation.GetConnectionProfiles();
      if (connectionProfiles.Count < 1)
      {
           return null;
      }
      var validProfiles = connectionProfiles.Where(profile =>
      {
           return (profile.IsWlanConnectionProfile && profile.GetNetworkConnectivityLevel() != NetworkConnectivityLevel.None);
      });
      if (validProfiles.Count() < 1)
      {
           return null;
      }
      ConnectionProfile firstProfile = validProfiles.First();
      return firstProfile.ProfileName;
 }
1
On

For future visitors of this post. netcmd.exe has been deprecated in IOT Core.

Microsoft Hardware Dev Center IoT Core Feature List (10/15/2018)

IOT_NETCMD (Deprecated)

Adds the command-line tool: netcmd.exe, used for configuring network connectivity. Deprecated in Windows 10, version 1803. The netcmd.exe will be removed when updating to version 1803. Use Windows.Devices.WiFi.WiFiAdapter for managing Wifi. See WiFi Connector example.

https://learn.microsoft.com/en-us/windows/iot-core/release-notes/currentcommercial