How to troubleshoot remote UWP AppService problems? - c#

I'm playing around with remote UWP AppServices in C# and I run into a very early roadblock: Getting a RemoteSystem instance.
I followed the tutorial on https://msdn.microsoft.com/en-us/windows/uwp/launch-resume/communicate-with-a-remote-app-service with my own code and I tried out the RemoteSystems sample as part of https://github.com/Microsoft/Windows-universal-samples
Unfortunately, the result is always the same.
First I request access to remote systems:
RemoteSystemAccessStatus status = await RemoteSystem.RequestAccessAsync();
This is successful: status has the value RemoteSystemAccessStatus.Allowed.
Next, I create a HostName instance:
var deviceHost = new HostName("computer2");
Then I want to get a RemoteSystem instance:
RemoteSystem remoteSystem = await RemoteSystem.FindByHostNameAsync(deviceHost);
This throws an exception:
Catastrophic failure (Exception from HRESULT: 0x8000FFFF (E_UNEXPECTED))
What I tried
Searching the web doesn't bring up much at this time (remote UWP AppServices are too new)
The event log doesn't have anything interesting in it
The Windows firewall seems to be configured correctly (this seems to be done automatically by Visual Studio)
What I'm looking for
One of my computer was upgraded from Windows 7 to Windows 10, the other from Windows 8.1 to Windows 10. So there is a chance my computers are "misconfigured" in some way (I remember the unnecessary task scheduler entries for Windows Media Center...)
My question: What are recommended practices to troubleshoot these kinds of problems? Are there tools that can help me? Right now I'm now even sure where to start looking...

Related

Project Rome - accessing Xbox console

I am experimenting with Project Rome and I am facing some issue with finding my Xbox console.
I can find my tablet, another laptop but I cannot find my Xbox console - it is a developer kit. I also tried to switch it to retail console but no difference.
private RemoteSystemWatcher remoteSystemWatcher;
remoteSystemWatcher = RemoteSystem.CreateWatcher();
remoteSystemWatcher.RemoteSystemAdded += OnDeviceAdded;
remoteSystemWatcher.Start();
private void OnDeviceAdded(RemoteSystemWatcher sender, RemoteSystemAddedEventArgs args)
{
}
I also tried to find Xbox console via HostName or IP, unfortunately it raises exception. Catastrophic failure (Exception from HRESULT: 0x8000FFFF (E_UNEXPECTED)). It seems like the same issue with this method as described here.
await RemoteSystem.FindByHostNameAsync(new HostName("...."));
It seems like a problem with specific version (10.0.14393.2113) of OS which I had installed before.
Right now I installed following version and it works without any problems.
Xbox One Recovery Update [14393.2152.161208-1218] December 14, 2016
Even this works if I use IP address of my Xbox console (with hostname it does not work).
await RemoteSystem.FindByHostNameAsync(new HostName("...."));

Xamarin/Android and the dread Bluetooth LE error 133 (GATT_ERROR)

I'm trying to write a cross-platform Xamarin Forms application (in C#) to talk to Bluetooth LE devices. I've downloaded a few packages (Plugin.BLE and Acr.Ble) and neither one works (they both scan but won't connect), so I thought I would try using the Android API directly to see if that would help me understand what's failing. BTW, I'm running on a Nexus 7 tablet running Android version 6.0.1.
I'm successfully scanning for devices:
BluetoothManager bluetoothManager = (BluetoothManager)Forms.Context.GetSystemService (Android.Content.Context.BluetoothService);
m_adapter = bluetoothManager.Adapter;
if ((m_adapter == null) || (!m_adapter.IsEnabled))
return false;
m_scanCallback = new BlueCallback (this);
m_adapter.BluetoothLeScanner.StartScan (m_scanCallback);
and I see the device I want to talk to (in this case, a TI development board MSP-EXP430F5438 in Server mode, running their SPPLE demo application). So I stop the scan:
m_adapter.BluetoothLeScanner.StopScan (m_scanCallback);
and then I connect to the desired device:
m_gattCallback = new BlueGattCallback ();
m_gatt = m_selectedDevice.ConnectGatt (Forms.Context, false, m_gattCallback);
and I pretty much immediately get a call back saying the connection failed:
BlueGattCallback.OnConnectionStateChange(gatt, status=133, newState=Disconnected)
I read this Google bug report so in my callback I tried calling Connect() directly in my callback:
if ( ((int)status == 133) && (numRetries < 10) )
{
numRetries++;
bool connect = gatt.Connect ();
Debug.WriteLine (" gatt.Connect() returned " + connect);
}
This code fails with error 133 repeatedly and quite quickly (all 10 retries take about 3 seconds).
Any idea what's going wrong here?
As this is dependant on the BLE stack which each vendor develops,
the error generally occurs on Samsung devices more than any other type, Android 6 being the most unstable.
So for anyone running into the 133 error and having many sleepless nights because of it. I would recommend using the Sweetblue
wrapper, you will however need to wrap the library yourself for use in C#.
It abstracts many of the unstable parts of BLE and provides good retry mechanisms as well as graceful degradation in certain cases.
But in the end this does not solve all problems and you will need to handle some of the instability yourself.

hresult from IMbnInterfaceManager::GetInterfaces when no MBN device exists

I have the following code working in Windows 7:
MbnInterfaceManager mbnInfMgr = new MbnInterfaceManager();
IMbnInterfaceManager mbnInfMgrInterface = mbnInfMgr as IMbnInterfaceManager;
if (mbnInfMgrInterface != null)
{
IMbnInterface[] mobileInterfaces = mbnInfMgrInterface.GetInterfaces() as IMbnInterface[];
}
No problems when the MBN device exists but when an MBN device doesn't exist I get the following exception in the call to GetInterfaces():
{System.Runtime.InteropServices.COMException (0x80070490): Element not found. (Exception from HRESULT: 0x80070490)
at MbnApi.IMbnInterfaceManager.GetInterfaces()
at foo.Program.configureConnection() in foo}
Question
Is there something that should be done to check for a MBN interface before calling GetInterfaces? I can simply catch this exception but I can't find any documentation that says this exception is the same as having no interfaces.
The closest thing I have found on statckoverflow is this
struggling with mobile broadband api windows 7 and windows 8 with C#, not sure what to install
which implies that maybe windows 7 behaves differently than windows 8.1.
I got the same Element not found exception trying to use GetSignalStrength() and MbnInterfaceManager I instead found you can obtain a lot of useful info using WMI. Please see the answer here using SELECT * FROM Win32_PerfRawData_Tcpip_NetworkInterface:
struggling with mobile broadband api windows 7 and windows 8 with C#, not sure what to install
UPDATE:
Please note that I found you cannot get the network info in Windows 8.1 in the same way as you do in Windows 7. See How can I install an application that requires WMI capabilities on Windows 8.1 to determine available bandwidth? and https://code.msdn.microsoft.com/windowsapps/network-information-sample-63aaa201

How can I configure network access for the Windows Phone emulator?

I'm trying to debug an application that is making a WebRequest synchronously, ie.:
HttpWebRequest req = WebRequest.Create(new Uri("http://www.stackoverflow.com/")) as HttpWebRequest;
IAsyncResult res = req.BeginGetResponse(callback => { }, req);
while (!res.IsCompleted)
{
System.Threading.Thread.Sleep(100);
}
// Doesn't matter what's here, as `res.IsCompleted` never returns true
This is just to check that some of the application logic is "right", but it's getting stuck, with the IAsyncResult never reporting itself as complete.
To check, things, I tried to use Internet Explorer on the emulator, but found that is unable to find any webpages (including the built in favourites), which makes me think that the emulator is trying to use a specific network interface on my laptop, but there doesn't seem to be any way to configure it, or which interface to use? I have a suspicion that it may be trying to use a VPN interface, or a virtual adaptor like the one for VirtualBox. So, how can I configure it? additionally, would you expect requests made by the emulator to show up in Fiddler?
For the record, NetworkInterface.GetIsNetworkAvailable() returns true;
UPDATE:
It appears that updating my graphics driver (and associated reboot) allowed the emulator to access the real network (or at least guess the right adapter); however, res.IsCompleted still doesn't report true (and Fiddler shows the request has completed), so I'm a little confuddled.
Are you using a proxy? The Windows Phone emulator is tied to the currently active Internet Connection, as well as the proxy settings. Make sure those are set up correctly. Also, there might be a firewall blocking Internet access for XDE - check the settings too.
I would recommend getting Fiddler. Attempt to configure it to capture emulator traffic and see what information you can get from there.

System.Management.ManagementException: Not found

I am running the following code:
ManagementClass oMClass = new ManagementClass("Win32_NetworkAdapterConfiguration");
ManagementObjectCollection colMObj = oMClass.GetInstances();
which is throwing this exception:
System.Management.ManagementException: Not found
at System.Management.ThreadDispatch.Start()
at System.Management.ManagementScope.Initialize()
at System.Management.ManagementObject.Initialize(Boolean getObject)
at System.Management.ManagementClass.GetInstances(EnumerationOptions options)
at System.Management.ManagementClass.GetInstances()
I went to check on the running services on Windows XP and found that Windows Management Instrumentation service has a status of 'Started'. I tried restarting the service but that didn't do any good.
I then tried to get the status of this service from within my running code using the ServiceController class:
ServiceController wpiService = new ServiceController();
wpiService.ServiceName = "Winmgmt";
string wmiStatus = wpiService.Status.ToString();
MessageBox.Show("WMI status= " + wmiStatus);
wmiStatus evaluates to 'Running'.
I have seen this error on only one of multiple machines running the same software. What's peculiar is that the machine was running smoothly for months, and then suddenly started showing this error.
Any clue as to what might be causing this?
I have also run into this issue. Here is one of the previously mentioned online resources explaining how one can fix WMI:
http://windowsxp.mvps.org/repairwmi.htm
The method of repairing seems to be different between different versions of Windows as explained on that page.
I had this problem on none of these versions, but on Windows Embedded Standard 2009. Since Windows XP Service Pack 2 is closest related to the listed OSes, that is the one I used:
For Windows XP Service Pack 2
Click Start, Run and type the following command:
rundll32 wbemupgd, UpgradeRepository
This command is used to detect and repair a corrupted WMI Repository. The results are stored in the setup.log (%windir%\system32\wbem\logs\setup.log) file.
The solution was to repair WMI on Windows XP. I don't have the detailed step by step fix (I'm not the one who implemented the fix), but my understanding is that a repository related to this service can get corrupted and there's a Windows utility that can repair it. There are several online resources on how to do this.

Categories