I have a UWP Windows 10 app intended to function as a SignalR client. I had this working before, but recently started getting this error: Error HRESULT E_FAIL has been returned from a call to a COM component
. Not sure what changed, nothing in weird in source control. It comes up when I try to trigger a background task via an ApplicationTrigger
.
Here is the code in my App.XML:
private void SignalR()
{
_hubConnection = new HubConnection("http://localhost/hollerhub");
_hubConnection.Credentials = CredentialCache.DefaultCredentials;
_toast = _hubConnection.CreateHubProxy("toast");
_toast.On<string>("broadcastMessage", msg =>
{
var localSettings = Windows.Storage.ApplicationData.Current.LocalSettings;
localSettings.Values["toastInfo"] = msg;
var appTrigger = new ApplicationTrigger();
appTrigger.RequestAsync().GetResults(); // <--- This is where the error is thrown
});
_hubConnection.Start();
}
The background task is registered at app start, but the ApplicationTrigger
is not reaching my background task code before failing. It is receiving the SignalR message just fine.
The problem was I had background tasks disabled for this app in my Windows 10 Privacy Settings.
System Settings => Privacy Settings => Background Apps
I discovered this during my background task registration as BackgroundExecutionManager.RequestAccessAsync()
was returning BackgroundAccessStatus.DeniedBySystemPolicy
.