0
votes

I develop native Windows 10 client LOB apps for a customer.
The environment: Windows 10 Pro (on the mobile clients / tablets and on the developer box), Visual Studio 2015 Professional with Update 3, all updates and patches installed. The client app uses the most recent „IBM MobileFirst SDK for Windows 8 Universal and Windows 10 Universal platforms“ version 8.0.2016070716

The application works very well when the application is online and the MobileFirst 8.0 server can be reached. We are experiencing application crashes of the client app if the server can not be reached (offline, MFP server stopped). It seems that a worker thread which is started from within the MobileFirst C# client library throws an exception. This exception can not be cathed in my code.

Here is some code to demonstrate the problem:

private async Task<WorklightAccessToken> ConnectMobileFirst()
{
    try
    {
        IWorklightClient _client = WorklightClient.CreateInstance();
        WorklightAuthorizationManager _wlauthManager = 
                        _client.AuthorizationManager;
        WorklightAccessToken temp1 = await
                         _wlauthManager.ObtainAccessToken("");
        return temp1;
    }
    catch (Exception exception)
    {
        Debug.WriteLine("Exception occured " + exception.Message);
        return null;
    }
}

Create a new blank app and call the above function from the OnLaunched eventhandler.

AccessToken = await ConnectMobileFirst();
if (AccessToken != null)
{
    Debug.WriteLine(AccessToken.IsValidToken
        ? "Connection OK, AccessToken is valid"
        : "AccesToken NOT valid");
}

If the MobileFirst Server can be reached everything works as expected and the AccessToken.IsValidToken is true.

If the MobileFirst Server is offline the following happens:

  • the function ConnectMobileFirst() finishes and a AccessToken object is returned (no exception occurs inside the method)
  • the AccessToken.IsValidToken is false (which is correct, since the MobileFirst server is offline).
  • Sometimes before and sometimes after the program can execute the Debug.WriteLine statement a other thread hits a NullReferenceException. This „other“ worker thread started somewhere inside the ObtainAccessToken() call inside the IBMMobileFirstPlatformFoundationWin10.dll. The Output window in Visual Studio contains the following information:

Exception thrown: 'System.Runtime.InteropServices.COMException' in mscorlib.ni.dll WinRT information: Die Serververbindung konnte nicht hergestellt werden.

Exception thrown: 'System.Runtime.InteropServices.COMException' in mscorlib.ni.dll WinRT information: Die Serververbindung konnte nicht hergestellt werden.

'MFPUnhandledExc1.exe' (CoreCLR: CoreCLR_UWP_Domain): Loaded 'D:\VS2015Projects\MFPUnhandledExc1\bin\x86\Debug\AppX\System.Resources.ResourceManager.dll'. Module was built without symbols. Exception thrown: 'System.Net.Http.HttpRequestException' in System.Net.Http.dll Exception thrown: 'System.Net.Http.HttpRequestException' in mscorlib.ni.dll Exception thrown: 'System.Net.Http.HttpRequestException' in System.Net.Http.dll Exception thrown: 'System.Net.Http.HttpRequestException' in mscorlib.ni.dll 'MFPUnhandledExc1.exe' (CoreCLR: CoreCLR_UWP_Domain): Loaded 'D:\VS2015Projects\MFPUnhandledExc1\bin\x86\Debug\AppX\System.Runtime.InteropServices.dll'. Cannot find or open the PDB file. Exception thrown: 'System.Net.Http.HttpRequestException' in mscorlib.ni.dll Exception thrown: 'System.Net.WebException' in System.Net.Requests.dll Exception thrown: 'System.NullReferenceException' in IBMMobileFirstPlatformFoundationWin10.dll

If you set a breakpoint on the line after the ConnectMobileFirst() call you can see there is a worker thread still active which has IBMMobileFirstPlatformFoundationWin10.dll in its call stack. This thread is not here anymore, if the backend connection is OK.

This behaviour can also be seen not only if the MobileFirst Server is offline but if the server is slow responding or the network is slow and the server response is big. Also this is not only during connect, but also during WorklightResourceRequest.send().

My questions:

  • What can I do to prevent this stray thread from killing my application? (a short term solution)
  • Why is there still a worker thread even if the call to ObtainAccessToken() has already finished?
  • And why is this thread not handling its exceptions?
3

3 Answers

1
votes

This is found as a bug in our client SDK code.And we have fixed it in the issue https://www-304.ibm.com/support/entdocview.wss?uid=swg1PI68253.

The fix will be published and will be available in nuget in the next nuget release.

0
votes

What can I do to prevent this stray thread from killing my application? Take a look at the Application.UnhandledException event, you can find documentation for this on MSDN via the below link. You can wire up this event in the App.xaml.cs code behind.

Normally after the UnhandledException event is fired, the Windows Runtime terminates the app because the exception was unhandled. The app code has some control over this: if the UnhandledException event handler sets the Handled property of the event arguments to true, then in most cases the app will not be terminated.

https://msdn.microsoft.com/en-us/library/windows/apps/windows.ui.xaml.application.unhandledexception

In regards to your other questions, I think you should have a read of this MSDN article on Exception handling for Windows Runtime apps in C# or Visual Basic which will help you understand what is going on with these exceptions in your app.

https://msdn.microsoft.com/en-us/library/windows/apps/dn532194

0
votes

We are able to reproduce the issue and we are working on the fix. We will update once we release the new version of SDK.