OneDrive / onedrive-sdk-csharp

OneDrive SDK for C#! https://dev.onedrive.com
Other
294 stars 143 forks source link

Crashes on Login on WM10 #173

Closed NPadrutt closed 2 weeks ago

NPadrutt commented 8 years ago

On windows mobile it crashes on login.

Exception of type 'Microsoft.Graph.ServiceException' was thrown.

The Message of the inner exception is:

Exception from HRESULT: 0x87B20C10 With this stack trace:

   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
   at Microsoft.OneDrive.Sdk.Authentication.WebAuthenticationBrokerWebAuthenticationUi.<AuthenticateAsync>d__0.MoveNext()

There are not really much more information..

My code looks like that:

try
            {
                var msaAuthenticationProvider = new MsaAuthenticationProvider(
                    ServiceConstants.MSA_CLIENT_ID,
                    ServiceConstants.RETURN_URL,
                    ServiceConstants.Scopes,
                    new CredentialVault(ServiceConstants.MSA_CLIENT_ID));

                await msaAuthenticationProvider.RestoreMostRecentFromCacheOrAuthenticateUserAsync();
                return new OneDriveClient(ServiceConstants.BASE_URL, msaAuthenticationProvider);
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex);
                throw new BackupException("Authentication Failed", ex);
            }

The Information above are from the catch here..

Interessting is, that it's only the first time. after that I have to restart the emulator to reproduce this behaviour again. On the physical device on the other hand it crashes all the time.

On the PC it works.

You'll find the project and the code here: https://github.com/MoneyFox/MoneyFox

It appears in the master branch.

cdmayer commented 8 years ago

Have you updated the Auth Adapter to 1.0.5? Recently added a fix that may affect this bug.

NPadrutt commented 8 years ago

Just tried it with the new version, but it behaves the same way.. I'll try it aswell when I deploy it to the device. Maybe it's an issue when it isn't published via the store.

NPadrutt commented 8 years ago

Btw, I have pretty much the same issue on android as well. I use there xamarin.auth and before upgrading to version 2.0 it worked as well.

RussWalton commented 8 years ago

Similar problem here on the Sample

It worked fine the first time I tried it (yesterday). Today I get..

Exception of type 'Microsoft.Graph.ServiceException' was thrown.

at Microsoft.Graph.HttpProvider.d19.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.OneDrive.Sdk.Authentication.OAuthHelper.d12.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.OneDrive.Sdk.Authentication.OAuthHelper.d10.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.OneDrive.Sdk.Authentication.MsaAuthenticationProvider.d32.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.OneDrive.Sdk.Authentication.MsaAuthenticationProvider.d30.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.OneDrive.Sdk.Authentication.MsaAuthenticationProvider.d26.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.OneDrive.Sdk.Authentication.MsaAuthenticationProvider.d25.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.TaskAwaiter.GetResult() at OneDrivePhotoBrowser.AccountSelection.d12.MoveNext() at Microsoft.Graph.HttpProvider.d19.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.OneDrive.Sdk.Authentication.OAuthHelper.d12.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.OneDrive.Sdk.Authentication.OAuthHelper.d10.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.OneDrive.Sdk.Authentication.MsaAuthenticationProvider.d32.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.OneDrive.Sdk.Authentication.MsaAuthenticationProvider.d30.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.OneDrive.Sdk.Authentication.MsaAuthenticationProvider.d26.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.OneDrive.Sdk.Authentication.MsaAuthenticationProvider.d25.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.TaskAwaiter.GetResult() at OneDrivePhotoBrowser.AccountSelection.d12.MoveNext()

cdmayer commented 8 years ago

I tried reproing your issue on an emulator and was unsuccessful. Authentication worked fine in both OnlineId and OAuth flows. Are either of you able to debug your device? It would be helpful to know what the exception code is (there are many types of Graph.ServiceException but the names are fairly descriptive).

NPadrutt commented 8 years ago

In my case I couldn't reproduce it on the emulator aswell.. it happend when I published it to the store..

NPadrutt commented 8 years ago

Ah, I just tried it on my lumia 950 Xl and there it crashes as well. Seems to be an issue with the actual device.

RussWalton commented 8 years ago

I thought about it later and it might be something that I did that caused the problem.

Once I had logged in successfully, I changed the scope, removed onedrive.readonly and added onedrive.appfolder

I'm currently using the old Live SDK and had often wondered what would happen if a user had granted certain permissions but the app later required different/additional permissions. If I set the scope back to onedrive.readonly it runs fine again,

The strange thing is though, if I look at my account "Apps and services you've given access to " I'm not seeing anything for the sample app, yet it's running fine now.

cdmayer commented 8 years ago

@RussWalton I'm not quite understanding the flow that you're describing... How does the LiveSDK come into play here?

Anyways, what's happening is that you already consented to onedrive.appfolder for the app. So even if you are only asking for onedrive.readonly right now, you earlier consented to greater permissions. Until you go through the explicit permission flow for that user again, you will be consenting to both scopes implicitly.

@NPadrutt If the only way to debug this is with a real device then it will require some more time. Can you modify your code a bit to be more explicit? Something like this:

try
{
...
}
catch (ServiceException serviceException)
{
    Debug.WriteLine(serviceException);
    throw new BackupException("Authentication Failed with Graph.ServiceException", serviceException);
}
catch (Exception ex)
{
    Debug.WriteLine(ex);
    throw new BackupException("Authentication Failed", ex);
}

The ServiceException type will give us much better info about what failed. At minimum, it will give us the throwsite and the error code, which should be a starting point.

RussWalton commented 8 years ago

I'm using the live SDK in my Windows 10 app currently. I was experimenting with the sample for onedrive SDK because I'd like to replace the LiveSDK with the OneDrive SDK.

So when I tried it yesterday, as I said I got the error if I changed the scope by removing onedrive.readonly and adding onedrive.appfolder. I've just tried it again and this time it went through the grant permission UI (which it didn't yesterday) and worked fine. I tried it a second time and all was well.

But I'm still not seeing any reference to this app in my "Apps and services you've given access to" in my MS Account management.

I'm only just getting familiar with this, so I'll keep on experimenting and see what I find.

Also FYI, I tried deploying to my Lumia 1520 and it also worked fine.

NPadrutt commented 8 years ago

I added the code you posted. The following is logged:

Exception thrown: 'Microsoft.Graph.ServiceException' in mscorlib.ni.dll The thread 0x1730 has exited with code 0 (0x0). The thread 0x16c4 has exited with code 0 (0x0). Code: authenticationFailure

The funny thing is, if you have the debugger in the catch it will show the login prompt. You can login, but when you go ahead debugging the app crashes obviously. If you go in again, the login prompt appears again, you can login again but this time without error. Third time it seems to work finally without crashing.

also funny: when I deinstall the app and install it again it works. Seems somehow like there is an issue when you authorize a device for the first time? o.O

cdmayer commented 8 years ago

@NPadrutt it seems like you are the only one experiencing the issue. I am still unable to repro this bug. If you can figure out a more definitive cause of the bug please post again here.

RussWalton commented 8 years ago

Maybe you can answer a basic question...

As I mentioned above I'm looking to replace the LiveSDK with the OneDrive SDK. I'm able to log in okay and create a onedrive client.

My question is does the onedrive sdk provide access to user info, such as their image etc. I realise I can manually use REST calls to get this information but I'm wondering if all this exists already in the SDK. I've looked around (admittedly not for too long) but I'm seeing anything obvious yet.

Thanks Russ

cdmayer commented 8 years ago

@RussWalton You called out one of the remaining few places where the LiveSDK has functionality the OneDrive API does not. You can get info about the signed-in user (such as their e-mail address) in LiveSDK. That is not currently supported in OneDrive API. However, this is one of only a tiny set of such limitations, so perhaps you can figure out a way to remove any blockers so that you can upgrade.

NPadrutt commented 8 years ago

I just made an update flight. Same as on the mobile: after the first login the app crashes.. all subsequent logins are successful. It seems there is an issue when you first login on a device..

Onotseike commented 7 years ago

Hi, I get this : Exception of type 'Microsoft.Graph.ServiceException' was thrown. invalidRequest Exception thrown: 'Microsoft.Graph.ServiceException' in mscorlib.ni.dll

when i try this: try { var appFolder = await OneDriveClient.Drive.Special.AppRoot.Request().GetAsync(); Debug.WriteLine(appFolder.Name); } catch (ServiceException e ) { Debug.WriteLine(e.Message +" " + e.Error.Code);

        }
baywet commented 2 weeks ago

Thank you for reaching out and for your patience. This SDK is being officially deprecated. See #259 for more information