【问题标题】:Unhandled IO error in a bootstrapper WPF(C#) .cs [closed]引导程序 WPF(C#).cs 中未处理的 IO 错误 [关闭]
【发布时间】:2020-05-15 11:30:18
【问题描述】:

New error好的,所以我遇到了一个错误,我不知道如何解决它,我们很乐意提供任何帮助。它在 WPF 2019 视觉工作室中。这是一个 .cs 程序 [program.cs]

   at System.Uri.CreateThis(String uri, Boolean dontEscape, UriKind uriKind)
   at System.Uri..ctor(String uriString)
   at Bootstrapper.Program.Main(String[] args) in C:\Users\raduf\Desktop\Exploit Template\Bootstrapper\Program.cs:line 40


System.UriFormatException: '无效的 URI:无法确定 URI 的格式。' System.UriFormatException HResult=0x80131537 Message=无效的 URI:无法确定 URI 的格式。此异常最初是在此调用堆栈中引发的:Program.cs 中的 [External Code] Bootstrapper.Program.Main(string[])

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Net;
using System.Diagnostics;

namespace Bootstrapper
{
    class Program
    {
        static String[] files = new string[]
        {
            "https://emaciated-blower.000webhostapp.com/Sploit/MeguSploit/",
        };

        static void Main(string[] args)
        {
            if (!Directory.Exists(Environment.CurrentDirectory + "/Exploit"))
            {
                Directory.CreateDirectory(Environment.CurrentDirectory + "/Exploit");
            }
            Console.Title = "MeguSploit Bootstrapper";
            Console.WriteLine("Updating....");

            foreach (Process process in Process.GetProcessesByName("MeguSploit"))
            {
                process.Kill();
            }

            foreach (string file in files)
            {
                string name = file.Substring(file.LastIndexOf("/") + 1);
                try
                {
                    new WebClient().DownloadFile(new Uri(file), Environment.CurrentDirectory + "/Exploit/" + name);
                }
                catch (IOException ex)  //HERE
                {

                }
            }
            Console.WriteLine("Updated...");
            Console.ForegroundColor = ConsoleColor.Green;
            Console.WriteLine("Please go to exploit folder and run the program. Make sure to always ru the bootstrapper to check for updates.");
            Console.ForegroundColor = ConsoleColor.White;
            Console.WriteLine("Press any key to close...");
            Console.ReadKey();
            Environment.Exit(0);
            Console.Read();



        }
    }
}

抱歉我的代码不好,我是这个世界的新手。我试图让它工作几个小时,但我做不到。 再次感谢。

【问题讨论】:

  • 错误是什么?
  • System.UriFormatException: '无效的 URI:无法确定 URI 的格式。' System.UriFormatException HResult=0x80131537 Message=无效的 URI:无法确定 URI 的格式。此异常最初是在此调用堆栈中引发的:Program.cs 中的 [External Code] Bootstrapper.Program.Main(string[])
  • 你有没有调试过你的代码来查看filename等的运行时值?在我看来,您的 files 数组似乎没有文件的 URI。
  • 是的,你去:ibb.co/WDzWd6H
  • file 的值是“dll”,这显然不是 URI。向后追溯以找出原因。

标签: c# .net wpf visual-studio


【解决方案1】:

我相信你的问题出在这一行

 string name = file.Substring(file.LastIndexOf("/") + 1);

根据您对文件数组的定义,这将为您提供一个空字符串作为名称。

    static String[] files = new string[]
    {
        "https://emaciated-blower.000webhostapp.com/Sploit/MeguSploit/",
    };

file.LastIndexOf("/") 将在 MeguSploit 之后获取 /

此外,除非您需要 Uri,否则您应该只对 WebClient().DownloadFile() 方法使用 string 重载。 (如下所示)

new WebClient().DownloadFile(file, Environment.CurrentDirectory + "/Exploit/" + name);

要下载多个文件,您需要定义正在下载的每个文件,如下所示。

static String[] files = new string[]
{
    "https://emaciated-blower.000webhostapp.com/Sploit/MeguSploit/test.exe",
    "https://emaciated-blower.000webhostapp.com/Sploit/MeguSploit/test.dll",
    // etc...
};

【讨论】:

  • 我很迷茫,很抱歉浪费了您的时间,但我真的不知道该怎么办。我尝试了你的代码,替换了(uri)一个,我得到 System.UriFormatException:'无效的 URI:无法确定 URI 的格式。'。我在 WPF 中待了大约 2 天,想开发一个程序的更新功能。另外,我的英语不是很好,但我明白你想说的话。我正在尝试下载 .dll 和 .exe 文件。
  • 我添加了新的错误照片。你可以更好地看到那里
  • 也不是要编辑评论
  • 它告诉你它找不到路径。您需要提供文件名。尝试将 new WebClient().DownloadFile(file, Environment.CurrentDirectory + "/Exploit/test.exe"); 之类的内容仅用于测试目的。
  • 当前您的name 对象为空。
猜你喜欢
  • 2016-07-10
  • 1970-01-01
  • 1970-01-01
  • 2010-11-12
  • 1970-01-01
  • 2014-06-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多