本文介绍了' System.ArgumentException'类型的异常发生在mscorlib.dll中,但未在用户代码= VB.Net中处理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的代码:-

导入System.Net
导入System.IO

公共类FormEyeL

   私有声明子keybd_event Lib"user32" (ByVal volumeUpDown作为字节,ByVal v1作为字节,ByVal v2作为整数,ByVal v3作为整数)

   私有子FormEyeL_Load(ByVal发送者作为对象,ByVal e作为EventArgs)处理MyBase.Load
        tmbSearchEngines.Items.Add("Teroticx")
        tmbSearchEngines.Items.Add(" Google")
        tmbSearchEngines.Items.Add("Wikipedia")
        tmbSearchEngines.Items.Add("Yahoo")

        tmbSearchEngines.SelectedItem = 0

       如果My.Settings.HomePageOrBlanK = 0则
            WebBrowser1.Navigate(My.Settings.HomePage)
       其他
       如果结束
   结束子

   私有子项butback_Click(按对象发送ByByVal,将其发送给EventArgs ByByVal)处理butback.Click
        WebBrowser1.GoBack()
   结束子

   私有子项butforward_Click(按对象发送ByVal发送者,按EventArgs接收ByVal e)处理butforward.Click
        WebBrowser1.GoForward()
   结束子

   私有Sub btnHome_Click(ByVal发送者作为对象,ByVal e作为EventArgs)处理btnHome.Click
        WebBrowser1.Navigate(My.Settings.HomePage)
   结束子

   私有Sub btnDownloads_Click(按对象发送ByVal发送者,按EventArgs接收ByVal e)处理btnDownloads.Click

   结束子

   私人Sub ToolStripButton3_Click(按对象发送发送者,按事件发送者发送ByBY)处理ToolStripButton3.Click
        WebBrowser1.Refresh()
   结束子

   私有子WebBrowser1_Navigated(ByVal发送者作为对象,ByVal e作为WebBrowserNavigatedEventArgs)处理WebBrowser1.Navigated
        textUrl.Text = WebBrowser1.Url.ToString
        webIcons()

        TabControl1.SelectedTab.Text = WebBrowser1.DocumentTitle.ToString

   结束子

   私人Sub textUrl_KeyUp(ByVal发送者作为对象,ByVal e作为KeyEventArgs)处理textUrl.KeyUp
       如果e.KeyCode = Keys.Enter然后
            WebBrowser1.Navigate(textUrl.Text)
       如果结束
   结束子

   私人子webIcons()

       昏暗的人作为新的WebClient
       作为新的MemoryStream昏暗的爱(ws.DownloadData("http://"& New Uri(WebBrowser1.Url.ToString).Host&"/favicon.ico"))
        Dim icon As New Icon(love

Imports System.Net
Imports System.IO

Public Class FormEyeL

    Private Declare Sub keybd_event Lib "user32" (ByVal volumeUpDown As Byte, ByVal v1 As Byte, ByVal v2 As Integer, ByVal v3 As Integer)

    Private Sub FormEyeL_Load(ByVal sender As Object, ByVal e As EventArgs) Handles MyBase.Load
        tmbSearchEngines.Items.Add("Teroticx")
        tmbSearchEngines.Items.Add("Google")
        tmbSearchEngines.Items.Add("Wikipedia")
        tmbSearchEngines.Items.Add("Yahoo")

        tmbSearchEngines.SelectedItem = 0

        If My.Settings.HomePageOrBlanK = 0 Then
            WebBrowser1.Navigate(My.Settings.HomePage)
        Else
        End If
    End Sub

    Private Sub butback_Click(ByVal sender As Object, ByVal e As EventArgs) Handles butback.Click
        WebBrowser1.GoBack()
    End Sub

    Private Sub butforward_Click(ByVal sender As Object, ByVal e As EventArgs) Handles butforward.Click
        WebBrowser1.GoForward()
    End Sub

    Private Sub btnHome_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnHome.Click
        WebBrowser1.Navigate(My.Settings.HomePage)
    End Sub

    Private Sub btnDownloads_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnDownloads.Click

    End Sub

    Private Sub ToolStripButton3_Click(ByVal sender As Object, ByVal e As EventArgs) Handles ToolStripButton3.Click
        WebBrowser1.Refresh()
    End Sub

    Private Sub WebBrowser1_Navigated(ByVal sender As Object, ByVal e As WebBrowserNavigatedEventArgs) Handles WebBrowser1.Navigated
        textUrl.Text = WebBrowser1.Url.ToString
        webIcons()

        TabControl1.SelectedTab.Text = WebBrowser1.DocumentTitle.ToString

    End Sub

    Private Sub textUrl_KeyUp(ByVal sender As Object, ByVal e As KeyEventArgs) Handles textUrl.KeyUp
        If e.KeyCode = Keys.Enter Then
            WebBrowser1.Navigate(textUrl.Text)
        End If
    End Sub

    Private Sub webIcons()

        Dim ws As New WebClient
        Dim love As New MemoryStream(ws.DownloadData("http://" & New Uri(WebBrowser1.Url.ToString).Host & "/favicon.ico"))
        Dim icon As New Icon(love

  此行出现错误.

 Getting error on this line.



       如果ImageList1.Images.Count = -1那么
            ImageList1.Images.Add(icon.ToBitmap)
            TabControl1.SelectedTab.ImageIndex = 0
       其他
            ImageList1.Images.Clear()
            ImageList1.Images.Add(icon.ToBitmap)
            TabControl1.SelectedTab.ImageIndex = 0
       如果结束
   结束子

   私有子tmbSearchEngines_KeyUp(ByVal发送者作为对象,ByVal e作为KeyEventArgs)处理tmbSearchEngines.KeyUp
       选择大小写(tmbSearchEngines.SelectedIndex)
           案例0
               如果e.KeyCode = Keys.Enter然后
                    WebBrowser1.Navigate("http://www.teroticx.com/" + tmbSearchEngines.Text)
               如果结束
           案例1
               如果e.KeyCode = Keys.Enter然后
                    WebBrowser1.Navigate(" https://www.google.co.in/#q=" + tmbSearchEngines.Text)
               如果结束
           情况2
               如果e.KeyCode = Keys.Enter然后
                    WebBrowser1.Navigate("https://zh.wikipedia.org/wiki/" + tmbSearchEngines.Text)
               如果结束
           情况3
               如果e.KeyCode = Keys.Enter然后
                    WebBrowser1.Navigate("https://in.yahoo.com/?p=us" + tmbSearchEngines.Text)
               如果结束

       结束选择
   结束子

   私有Sub btnVolumeUp_Click(ByVal发送者作为对象,ByVal e作为EventArgs)处理btnVolumeUp.Click
       调用keybd_event(System.Windows.Forms.Keys.VolumeUp,0,0,0)
   结束子

   私有Sub btnVolumeDown_Click(ByVal发送者作为对象,ByVal e作为EventArgs)处理btnVolumeDown.Click
       调用keybd_event(System.Windows.Forms.Keys.VolumeDown,0,0,0)
   结束子

    Private Sub OptionsToolStripMenuItem_Click(ByVal发送者作为对象,ByVal e作为EventArgs)处理OptionsToolStripMenuItem.Click
        frmoption.Show()
   结束子

   私有Sub tmrDate_Tick(发送者为对象,e作为EventArgs)处理tmrDate.Tick
        lblDate.Text =现在
   结束子
结束类



        If ImageList1.Images.Count = -1 Then
            ImageList1.Images.Add(icon.ToBitmap)
            TabControl1.SelectedTab.ImageIndex = 0
        Else
            ImageList1.Images.Clear()
            ImageList1.Images.Add(icon.ToBitmap)
            TabControl1.SelectedTab.ImageIndex = 0
        End If
    End Sub

    Private Sub tmbSearchEngines_KeyUp(ByVal sender As Object, ByVal e As KeyEventArgs) Handles tmbSearchEngines.KeyUp
        Select Case (tmbSearchEngines.SelectedIndex)
            Case 0
                If e.KeyCode = Keys.Enter Then
                    WebBrowser1.Navigate("http://www.teroticx.com/" + tmbSearchEngines.Text)
                End If
            Case 1
                If e.KeyCode = Keys.Enter Then
                    WebBrowser1.Navigate("https://www.google.co.in/#q=" + tmbSearchEngines.Text)
                End If
            Case 2
                If e.KeyCode = Keys.Enter Then
                    WebBrowser1.Navigate("https://en.wikipedia.org/wiki/" + tmbSearchEngines.Text)
                End If
            Case 3
                If e.KeyCode = Keys.Enter Then
                    WebBrowser1.Navigate("https://in.yahoo.com/?p=us" + tmbSearchEngines.Text)
                End If

        End Select
    End Sub

    Private Sub btnVolumeUp_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnVolumeUp.Click
        Call keybd_event(System.Windows.Forms.Keys.VolumeUp, 0, 0, 0)
    End Sub

    Private Sub btnVolumeDown_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnVolumeDown.Click
        Call keybd_event(System.Windows.Forms.Keys.VolumeDown, 0, 0, 0)
    End Sub

    Private Sub OptionsToolStripMenuItem_Click(ByVal sender As Object, ByVal e As EventArgs) Handles OptionsToolStripMenuItem.Click
        frmoption.Show()
    End Sub

    Private Sub tmrDate_Tick(sender As Object, e As EventArgs) Handles tmrDate.Tick
        lblDate.Text = Now
    End Sub
End Class


例外 详细信息-

System.ArgumentException未通过用户代码处理
  HResult = -2147024809
 不支持Message = URI格式.
 来源= mscorlib
  StackTrace:
        at System.IO.Path.LegacyNormalizePath(字符串路径,布尔值fullCheck,Int32 maxPathLength,布尔值expandShortPaths)
        at System.IO.Path.NormalizePath(字符串路径,布尔值fullCheck,Int32 maxPathLength,布尔值expandShortPaths)
        at System.IO.Path.GetFullPathInternal(String path)
        at System.Net.WebClient.GetUri(字符串路径)
        at System.Net.WebClient.DownloadData(字符串地址)
     在C:\ Users \ Abir Maheshwari \ documents \ visual studio 2015 \ Projects \ EyeL \ EyeL \ Form1.vb中的EyeL.FormEyeL.webIcons()中:第59行
     在C:\ Users \ Abir Maheshwari \ documents \ visual studio 2015 \ Projects \ EyeL \ EyeL \ Form1.vb:line 44中的EyeL.FormEyeL.WebBrowser1_Navigated(对象发送者,WebBrowserNavigatedEventArgs e)中        at System.Windows.Forms.WebBrowser.OnNavigated(WebBrowserNavigatedEventArgs e)
        at System.Windows.Forms.WebBrowser.WebBrowserEvent.NavigateComplete2(Object pDisp,Object& urlObject)
  InnerException: 

System.ArgumentException was unhandled by user code
  HResult=-2147024809
  Message=URI formats are not supported.
  Source=mscorlib
  StackTrace:
       at System.IO.Path.LegacyNormalizePath(String path, Boolean fullCheck, Int32 maxPathLength, Boolean expandShortPaths)
       at System.IO.Path.NormalizePath(String path, Boolean fullCheck, Int32 maxPathLength, Boolean expandShortPaths)
       at System.IO.Path.GetFullPathInternal(String path)
       at System.Net.WebClient.GetUri(String path)
       at System.Net.WebClient.DownloadData(String address)
       at EyeL.FormEyeL.webIcons() in C:\Users\Abir Maheshwari\documents\visual studio 2015\Projects\EyeL\EyeL\Form1.vb:line 59
       at EyeL.FormEyeL.WebBrowser1_Navigated(Object sender, WebBrowserNavigatedEventArgs e) in C:\Users\Abir Maheshwari\documents\visual studio 2015\Projects\EyeL\EyeL\Form1.vb:line 44
       at System.Windows.Forms.WebBrowser.OnNavigated(WebBrowserNavigatedEventArgs e)
       at System.Windows.Forms.WebBrowser.WebBrowserEvent.NavigateComplete2(Object pDisp, Object& urlObject)
  InnerException: 

由于我的项目被卡住,请为此寻找解决方案.

推荐答案

Imports System.IO
Imports System.Net

Public Class Form1

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        ImageList1.ImageSize = New Size(16, 16)
        TabControl1.ImageList = ImageList1
    End Sub

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Dim browserUrl As String = "https://www.google.com/"

        Dim bm As Bitmap = GetFavIcon(browserUrl)
        If bm IsNot Nothing Then
            If ImageList1.Images(browserUrl) Is Nothing Then
                ImageList1.Images.Add(browserUrl, bm)
            End If
            TabControl1.SelectedTab.ImageKey = browserUrl
        End If
    End Sub

    Private Function GetFavIcon(url As String) As Bitmap
        Dim FavIconBitmap As Bitmap = Nothing
        Dim TheUri As New Uri(url)
        If TheUri.HostNameType = UriHostNameType.Dns Then
            Dim FavIcoUrl As String = "http://" & TheUri.Host & "/favicon.ico"
            Dim req As WebRequest = HttpWebRequest.Create(FavIcoUrl)
            Using res As HttpWebResponse = CType(req.GetResponse, HttpWebResponse)
                Using strm As Stream = res.GetResponseStream
                    FavIconBitmap = New Bitmap(strm)
                End Using
            End Using
        End If
        Return FavIconBitmap
    End Function
End Class

 


这篇关于' System.ArgumentException'类型的异常发生在mscorlib.dll中,但未在用户代码= VB.Net中处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-01 10:37