OneDrive / onedrive-sdk-csharp

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

I get Exception of type 'Microsoft.Graph.ServiceException' was thrown. invalidRequest Exception thrown: 'Microsoft.Graph.ServiceException' in mscorlib.ni.dll #196

Closed Onotseike closed 7 years ago

Onotseike commented 7 years ago

Hi, I am integrating Onedrive SDK with the UWP part of my Xamarin App. Once I press the download button I get the Onedrive signin page but it throws the above error in this line:

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

    }`

here is the full relevant code:

 `    public async Task Download(string filename)
{
    //AccountSelectionLoaded();
    await InitializeClient();
    try
    {
        var appFolder = await OneDriveClient.Drive.Special.AppRoot.Request().GetAsync();
        Debug.WriteLine(appFolder.Name);
    }
    catch (ServiceException e  )
    {
        Debug.WriteLine(e.Message +"    " +  e.Error.Code);

    }

    var file = await OneDriveClient.Drive.Special.AppRoot.Children[filename].Content.Request().GetAsync();

    //var fileStream = await fileBuilder.Content.Request().GetAsync();

    IStorageFile appFile = await ApplicationData.Current.LocalFolder.CreateFileAsync("test.db3",
                        CreationCollisionOption.OpenIfExists);
    byte[] fileBytes;
   using (DataReader reader = new DataReader(file.AsInputStream()))
        {
            fileBytes = new byte[file.Length];
            await reader.LoadAsync((uint)file.Length);
            reader.ReadBytes(fileBytes);
        }
   Debug.WriteLine(fileBytes.Length);
    Debug.WriteLine("Writing");
    await FileIO.WriteBytesAsync(appFile, fileBytes);
    Debug.WriteLine("End of writing");       
}`

` private async Task InitializeClient() { if (OneDriveClient == null) { Task authTask; var msaAuthProvider = new MsaAuthenticationProvider(oneDriveConsumerClientId,oneDriveConsumerReturnUrl,scopes); await msaAuthProvider.AuthenticateUserAsync(); OneDriveClient = new OneDriveClient(oneDriveConsumerBaseUrl, msaAuthProvider);

        AuthenticationProvider = msaAuthProvider;

    }
}`
gjohncock commented 7 years ago

try pausing your virus protection. I am using Kaspersky EndPoint 10 and when I pause the protection everything works fine. I am still trying to work out what exception needs to be added to make this work with Kaspersky