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

  显示原文与译文双语对照的内容
0 0

我试图上传一个文件到 OneDrive 。 我成功地连接和验证 OneDrive,但当试图上载时,我将得到错误: Object reference not set to an instance of an object.

代码是:

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 方法引发异常。 oneDriveFolderId 设置并存在于OneDrive中。 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()

我将上传代码修改为:

LiveUploadOperation operation = await liveClient.CreateBackgroundUploadAsync(
 oneDriveFolderId, 
 DatabaseBackupname, 
 toUploadStream, 
 OverwriteOption.DoNotOverwrite);
await operation.StartAsync();

并且 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()
时间:原作者:3个回答

0 0

这个方法并不是对错误消息的解决方案,但是我把 Live.SDK 引用改为 Windows Phone dll,现在我可以使用 BackgroundUploadAsync ( 路径,uri,覆盖) 方法,它可以运行。

我还必须更改认证方法。

原作者:
0 0

我在这个问题上浪费了几个小时。 对我来说,它发生在一个 Windows Phone 8.0应用程序上,我正在迁移到 Windows Phone 8.1 Silverlight 。 最后解决的事情就是更新到 Windows Phone 最新的for广告 SDK 。 我从 6.2.960.0 版本到 8.1.501 12.0. 我重新生成后,我的上传到OneDrive开始完美的工作。 不确定 root 原因是什么但是我认为我会在这里共享它以帮助任何人。

要清楚,我的项目文件从以下位置开始:

<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"/>
原作者:
0 0

我不得不把我的应用"关联"商店。"

右键单击 Visual Studio 中解决方案资源管理器中的项目行。

左点击商店-> 关联应用与商店

我必须注册为,开发人员( 为它付费),但是一旦我做到了,我的调用返回了合理的值。

因为这是我最终要走的方向,我想,这是什么东西。

原作者:
...