简体   繁体   English

无法将类型隐式转换为system.net

[英]Cannot Implicitly Convert Type to system.net

I am having an error in my program when trying to download files from a remote server, I am using the System.Net Lib and it is having an issue converting to it. 尝试从远程服务器下载文件时,程序中出现错误,我使用的是System.Net Lib,转换为它时出现问题。

I am getting the error Message 我收到错误消息

Cannot implicitly convert type 'System.ComponentModel.AsyncCompletedEventHandler' to System.Net.DownloadProgressChangedEventHandler' 无法将类型'System.ComponentModel.AsyncCompletedEventHandler'隐式转换为System.Net.DownloadProgressChangedEventHandler'

on the last line in the code block 在代码块的最后一行

AsyncCompletedEventHandler(client_DownloadFileCompleted);

Error Line ^ 错误行^

Form.cs V Form.cs V

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Net;

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

        private void Form1_Load(object sender, EventArgs e)
        {

        }

        private void btnStartDownload_Click(object sender, EventArgs e)
        {
            prgDownload.Visible = true;
                WebClient client = new WebClient();
                client.DownloadProgressChanged += new
                DownloadProgressChangedEventHandler(client_DownloadProgressChanged);
                client.DownloadProgressChanged += new
                AsyncCompletedEventHandler(client_DownloadFileCompleted);

I would be very grateful if anyone had a way to resolve this or a workaround to get the same result, thanks :) 如果有人有办法解决这个问题或解决方法以获得相同的结果,我将非常感谢,谢谢:)

You probably meant to write client.DownloadFileCompleted on your last line. 您可能打算在最后一行编写client.DownloadFileCompleted

You currently have two calls to DownloadProgressChanged , one with a matching delegate type ( DownloadProgressChangedEventHandler ), one with the wrong one ( AsyncCompletedEventHandler ). 当前,您有两个对DownloadProgressChanged调用,一个具有匹配的委托类型( DownloadProgressChangedEventHandler ),一个具有错误的委托类型( AsyncCompletedEventHandler )。

You use incorrect delegate in subscription to the event on last line. 您在最后一行的事件订阅中使用了不正确的delegate

If you use Visual Studio, write += and press Tab key, so the method with correct signature will be generated. 如果使用Visual Studio,请编写+=并按Tab键,这样将生成具有正确签名的方法。

But I see that a couple of lines above you already subscribed to the same event, so my impression is that you don't use a correct event for that what you want to achieve. 但是我看到您上方的两行已经订阅了同一事件,因此我的印象是,对于要实现的目标,您没有使用正确的事件。

There should be DownloadFileCompleted event. 应该DownloadFileCompleted事件。 I presume that is what you want. 相信这是你想要的。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 无法将类型隐式转换为System.Net.Authorization? - Cannot implicitly convert type to System.Net.Authorization? 无法将类型 ('string', 'string') 隐式转换为 System.Net.ICredentialsByHost - Cannot implicitly convert type ('string', 'string') to System.Net.ICredentialsByHost System.Net,无法解析符号“Net” - System.Net, cannot resolve symbol 'Net' 无法将类型“system.net.http.httpresponsemessage”隐式转换为“system.web.httpresponse” - cannot implicitly convert type 'system.net.http.httpresponsemessage' to 'system.web.httpresponse' 无法将类型“System.Web.Http.Results.BadRequestErrorMessageResult”隐式转换为“System.Net.Http.HttpResponseMessage” - Cannot implicitly convert type 'System.Web.Http.Results.BadRequestErrorMessageResult' to 'System.Net.Http.HttpResponseMessage' 无法将类型'System.Version'隐式转换为'System.Net.HttpVersion' - Cannot implicitly convert type 'System.Version' to 'System.Net.HttpVersion' 无法将类型“System.Net.Mail.MailAddress”隐式转换为“SendGrid.Helpers.Mail.EmailAddress” - Cannot implicitly convert type 'System.Net.Mail.MailAddress' to 'SendGrid.Helpers.Mail.EmailAddress' 无法在 asp.net MVC 中隐式转换类型 'System.Collections.Generic.List - Cannot implicitly convert type 'System.Collections.Generic.List in asp.net MVC 无法将类型 Android.Net.Uri 隐式转换为 System.Uri - Cannot implicitly convert type Android.Net.Uri to System.Uri 不能隐式转换类型System.DateTime? 到System.DateTime - cannot implicitly convert type System.DateTime? to System.DateTime
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM