调用的目标引发了异常吗?

时间:2017-10-19 19:21:00

标签: c# .net winforms youtube

我有一个例外,我无法找到解决问题的方法。我认为我的整个代码都是有效的c#。

namespace YoutubeDownloader2Form
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private async void button1_Click(object sender, EventArgs e)
        {
            DownloadUrl DownloadUrl = new DownloadUrl();


            List<Class1> FinalLiast = DownloadUrl.DownloadUrlMethod(textBox1.Text);
            int i = 0;
            foreach (var Urls in FinalLiast)
            {
                string Authorization = Urls.Author;

                IEnumerable<VideoInfo> videoInfos = DownloadUrlResolver.GetDownloadUrls(Urls.Url);

                VideoInfo Video = videoInfos.First(info => info.VideoType == VideoType.Mp4 && info.Resolution == 144);

                if (Video.RequiresDecryption)
                {
                    DownloadUrlResolver.DecryptDownloadUrl(Video);
                }

                string path = Directory.CreateDirectory(@"C:\Youtube\" + Authorization).ToString();
                var videoDownloader = new VideoDownloader(Video,
                    Path.Combine((@"C:\youtube\" + path), Video.Title + Video.VideoExtension));


                StreamWriter dosya = File.AppendText((@"C:\youtube\" + path) + i + ".txt");

                videoDownloader.Execute();
                //Thread.Sleep(60000);
                i++;
            }
        }
    }
}

public class DownloadUrl
{
    public List<Class1> DownloadUrlMethod(string txtboxDeger)
    {

        VideoSearch Items = new VideoSearch();
        List<Class1> ListClass1 = new List<Class1>();

        string searchCount =
            txtboxDeger + "&sp=EgIYAVAU";
        foreach (var Item in Items.SearchQuery(searchCount, 1))
        {
            Class1 Video = new Class1();
            Video.title = Item.Title;
            Video.Author = Item.Author;
            Video.Url = Item.Url;
            IEnumerable<VideoInfo> videos = DownloadUrlResolver.GetDownloadUrls(Video.Url);
            ListClass1.Add(Video);

        }
        return ListClass1;
    }
}

代码适用于三个查询,但我有20个。在3.步骤,它抛出一个异常;这是堆栈跟踪:

  

at System.RuntimeMethodHandle.InvokeMethod(Object target,Object [] arguments,Signature sig,Boolean constructor)          at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj,Object [] parameters,Object [] arguments)          在System.Delegate.DynamicInvokeImpl(Object [] args)          在System.Windows.Forms.Control.InvokeMarshaledCallbackDo(ThreadMethodEntry tme)          在System.Windows.Forms.Control.InvokeMarshaledCallbackHelper(Object obj)          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)          在System.Threading.ExecutionContext.Run(ExecutionContext executionContext,ContextCallback回调,对象状态)          在System.Windows.Forms.Control.InvokeMarshaledCallback(ThreadMethodEntry tme)          在System.Windows.Forms.Control.InvokeMarshaledCallbacks()          在System.Windows.Forms.Control.WndProc(消息&amp; m)          在System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message&amp; m)          在System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message&amp; m)          在System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd,Int32 msg,IntPtr wparam,IntPtr lparam)          在System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG&amp; msg)          在System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID,Int32 reason,Int32 pvLoopData)          在System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason,ApplicationContext context)          在System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason,ApplicationContext context)          在System.Windows.Forms.Application.Run(Form mainForm)          在C:\ Users \ Ramazan BIYIK \ source \ repos \ YoutubeDownloader2Form \ YoutubeDownloader2Form \ Program.cs中的YoutubeDownloader2Form.Program.Main():第26行&gt;&gt;

This is the error zone

您可以从图片中看到代码抛出的位置。我尝试异步,它也抛出。我检查了InnerException;它说不支持给定路径的格式。但是,它成功下载了前三个视频。它也适用于其他视频。

为什么这段代码会抛出异常?

我按照这些教程编写了这段代码:

https://www.youtube.com/watch?v=kv63n_rfJwk

https://www.youtube.com/watch?v=TnG3urCD_m0

0 个答案:

没有答案