Windows phone 8.1 BackgroundUploadAsync错误对象未设置为实例

Windows phone 8.1 BackgroundUploadAsync错误对象未设置为实例,windows-phone-8.1,onedrive,live-sdk,Windows Phone 8.1,Onedrive,Live Sdk,我试图将文件上载到OneDrive。我正在成功连接到OneDrive并对其进行身份验证,但在尝试上载时,出现错误:对象引用未设置为对象的实例。 代码是: IsolatedStorageFile iso = IsolatedStorageFile.GetUserStoreForApplication(); // Release all resources from DB App.AppViewModel.DisposeCurrentDB(); IsolatedStorageFileStream

我试图将文件上载到OneDrive。我正在成功连接到OneDrive并对其进行身份验证,但在尝试上载时,出现错误:
对象引用未设置为对象的实例。

代码是:

IsolatedStorageFile iso = IsolatedStorageFile.GetUserStoreForApplication();
// Release all resources from DB 
App.AppViewModel.DisposeCurrentDB();

IsolatedStorageFileStream toUploadStream = iso.OpenFile(AppResources.DatabaseName + ".sdf", FileMode.Open);

LiveConnectClient liveClient = new LiveConnectClient(oneDriveAuthClient.Session);

try
{
    LiveOperationResult uploadResult = await liveClient.BackgroundUploadAsync(
        oneDriveFolderId, 
        DatabaseBackupname, 
        toUploadStream.AsInputStream(),
        OverwriteOption.Overwrite);

    dynamic result = uploadResult.Result;
    MessageBox.Show("Upload successful. Uploaded to " + result.source);
}
catch (LiveConnectException ex)
{
    MessageBox.Show("Error uploading backup: " + ex.Message);
}

App.AppViewModel.RefreshCurrentDB();
BackgroundUploadAysnc
方法引发异常。OneDrive中已设置并存在
OneDrive文件夹ID
。DatabaseBackupname是OneDrive中不存在的正确新文件名。我在调试器中检查了流,发现这个对象不是空的,并且有一个大小

Stacktrace
   at Microsoft.Live.Operations.TailoredUploadOperation.<OnGetUploadLinkCompleted>d__4.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.AsyncMethodBuilderCore.<ThrowAsync>b__4(Object state)
   at System.Threading.QueueUserWorkItemCallback.WaitCallback_Context(Object state)
   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   at System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem()
   at System.Threading.ThreadPoolWorkQueue.Dispatch()
   at System.Threading._ThreadPoolWaitCallback.PerformWaitCallback()
并且
CreateBackgroundUploadAsync
方法引发以下异常:

Message = "Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))"
   at Windows.Networking.BackgroundTransfer.BackgroundUploader.CreateUploadFromStreamAsync(Uri uri, IInputStream sourceStream)
   at Microsoft.Live.Operations.CreateBackgroundUploadOperation.<OnGetUploadLinkCompleted>d__0.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.AsyncMethodBuilderCore.<ThrowAsync>b__4(Object state)
   at System.Threading.QueueUserWorkItemCallback.WaitCallback_Context(Object state)
   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   at System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem()
   at System.Threading.ThreadPoolWorkQueue.Dispatch()
   at System.Threading._ThreadPoolWaitCallback.PerformWaitCallback()
Message=“访问被拒绝。(来自HRESULT的异常:0x80070005(E_ACCESSDENIED))”
在Windows.Networking.BackgroundTransfer.BackgroundUploader.CreateUploadFromStreamAsync(Uri,IIInputStream sourceStream)
在Microsoft.Live.Operations.CreateBackgroundUploadOperation.d_u0.MoveNext()上
---来自引发异常的上一个位置的堆栈结束跟踪---
在System.Runtime.CompilerServices.AsyncMethodBuilderCore.b__4(对象状态)中
位于System.Threading.QueueUserWorkItemCallback.WaitCallback_上下文(对象状态)
位于System.Threading.ExecutionContext.RunInternal(ExecutionContext ExecutionContext、ContextCallback回调、对象状态、布尔值preserveSyncCtx)
在System.Threading.ExecutionContext.Run(ExecutionContext ExecutionContext,ContextCallback回调,对象状态,布尔保存SyncCTX)
位于System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem()处
在System.Threading.ThreadPoolWorkQueue.Dispatch()中
在System.Threading.\u ThreadPoolWaitCallback.PerformWaitCallback()中

这并不是错误消息的真正解决方案,但我将Live.SDK引用更改为Windows Phone dll,现在我可以使用BackgroundUploadAsync(path,uri,overwrite)方法,并且可以正常工作


我还必须更改Auth方法。

我在这个问题上浪费了几个小时。对我来说,它发生在我正在迁移到WindowsPhone8.1Silverlight的WindowsPhone8.0应用程序上。对我来说,最终解决问题的是更新到最新的微软广告SDK for Windows Phone。我从版本6.2.960.0升级到了8.1.50112.0。在那之后,我一重建,我上传到OneDrive的工作就开始完美。根本不确定根本原因是什么,但我想我会在这里分享,以防它对任何人都有帮助

明确地说,我的项目文件来自以下内容:

<Reference Include="Microsoft.Advertising.Mobile, Version=6.2.960.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL" />
<Reference Include="Microsoft.Advertising.Mobile.UI, Version=6.2.960.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL" />

为此:

<Reference Include="Microsoft.Advertising.Mobile, Version=8.1.50112.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL" />
<Reference Include="Microsoft.Advertising.Mobile.Common, Version=8.1.50112.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL" />
<Reference Include="Microsoft.Advertising.Mobile.UI, Version=8.1.50112.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL" />

我不得不将我的应用程序与商店“关联起来”

在VisualStudio的解决方案资源管理器中的项目行上单击鼠标右键

左键单击商店->将应用程序与商店关联

我必须注册成为微软的开发者(并为此付费),但一旦我注册了,我对BackgroundUploadAsync的调用返回了合理的值

因为它把我带向了我最终将要走的方向,我想,这到底是怎么回事

<Reference Include="Microsoft.Advertising.Mobile, Version=8.1.50112.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL" />
<Reference Include="Microsoft.Advertising.Mobile.Common, Version=8.1.50112.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL" />
<Reference Include="Microsoft.Advertising.Mobile.UI, Version=8.1.50112.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL" />