通过wcf服务将视频上传到youtube时出现异常(Google.Apis.YouTube.v3)

时间:2017-01-18 14:22:53

标签: c# api youtube upload

有时它的工作正常,但有些人得到了这个未知的异常

  

对象引用未设置为对象的实例。 System.Collections.ListDictionaryInternal at BusinessClass.videosInsertRequest_ProgressChanged(IUploadProgress progress)at Google.Apis.Upload.ResumableUpload' 1.d__84.MoveNext()---从之前位置抛出异常的堆栈跟踪结束---在系统中位于System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()的System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务)中的.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务任务)... d__102.MoveNext()对象引用未设置为对象的实例。 Void videosInsertRequest_ProgressChanged(Google.Apis.Upload.IUploadProgress)

    using (var fileStream = new FileStream(filePath, FileMode.Open))
                {
                    const int KB = 0x400;
                    var minimumChunkSize = 256 * KB;

                    var videosInsertRequest = youtubeService.Videos.Insert(video, "snippet,status", fileStream, "video/*");
                    videosInsertRequest.ProgressChanged += videosInsertRequest_ProgressChanged;
                    videosInsertRequest.ResponseReceived += videosInsertRequest_ResponseReceived;

                    videosInsertRequest.ChunkSize = minimumChunkSize * 4;
                    //videosInsertRequest.Upload();
                    await videosInsertRequest.UploadAsync();
                }

 void videosInsertRequest_ProgressChanged(Google.Apis.Upload.IUploadProgress progress)
        {
            switch (progress.Status)
            {
                case UploadStatus.Uploading:
                    //Console.WriteLine("{0} bytes sent.", progress.BytesSent);
                    break;

                case UploadStatus.Failed:
                    BusinessClass objBusiness = new BusinessClass();
                    objBusiness.writeExceptionLog("videosInsertRequest_ProgressChanged", progress.Exception.InnerException.ToString());

                    //Console.WriteLine("An error prevented the upload from completing.\n{0}", progress.Exception);
                    break;
            }
        }

        void videosInsertRequest_ResponseReceived(Video video)
        {
            getVideoID = video.Id;
            //string getVideoID = video.Id;
            //Console.WriteLine("Video id '{0}' was successfully uploaded.", video.Id);
        }

0 个答案:

没有答案