Getting error msg at runtime 'Unhandled exception has occurred in your application. If you click continue'

huangapple go评论80阅读模式
英文:

Getting error msg at runtime 'Unhandled exception has occurred in your application. If you click continue'

问题

我有一个用VB编写的ClickOnce应用程序,是在2015版的Visual Studio中创建的。当有人首次点击我发送给他们的.exe文件时,他们会收到以下消息:"您的应用程序发生了未处理的异常。如果点击继续,应用程序将忽略此错误并尝试继续..."

如果用户点击继续,然后关闭并重新启动应用程序,他们将不再收到此消息。但我不知道这种情况会持续多久。我之所以这么说是因为我在多次完全正常运行后才能看到代码中发生异常的地方,然后偶尔会看到异常。所以它并不一致,让我感到困惑。

以下是发生异常的代码:

Dim UpfileNames As Object = My.Computer.FileSystem.GetFiles(spath, FileIO.SearchOption.SearchTopLevelOnly, "DR087*.OLD")

spath是一个链接到我们网络服务器上以IIS设置的“共享”文件夹,它作为密钥存储在我们Web服务的web.config文件中,密钥为"FileLocationSharePath",值为"\erdtd4587\DataStorage"

以下是在异常实际发生时,我在Visual Studio中收到的异常信息。对于任何帮助,我都非常感激。

System.IO.IOException was unhandled
  HResult=-2146500602
  Message=Invalid Signature.

  Source=mscorlib
  StackTrace:
       at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
       at System.IO.FileSystemEnumerableIterator`1.CommonInit()
       at System.IO.FileSystemEnumerableIterator`1..ctor(String path, String originalUserPath, String searchPattern, SearchOption searchOption, SearchResultHandler`1 resultHandler, Boolean checkHost)
       at System.IO.Directory.GetFiles(String path, String searchPattern)
       at Microsoft.VisualBasic.FileIO.FileSystem.FindPaths(FileOrDirectory FileOrDirectory, String directory, String wildCard)
       at Microsoft.VisualBasic.FileIO.FileSystem.FindFilesOrDirectories(FileOrDirectory FileOrDirectory, String directory, SearchOption searchType, String[] wildcards, Collection`1 Results)
       at Microsoft.VisualBasic.FileIO.FileSystem.FindFilesOrDirectories(FileOrDirectory FileOrDirectory, String directory, SearchOption searchType, String[] wildcards)
       at Microsoft.VisualBasic.MyServices.FileSystemProxy.GetFiles(String directory, SearchOption searchType, String[] wildcards)
       at APRS.frmReportViewer.frmReportViewer_Load(Object sender, EventArgs e) in C:\Working\APRS-SASR\APRS4.9\APRSApplication\Forms\frmReportViewer.vb:line 29
       at System.Windows.Forms.Form.OnLoad(EventArgs e)
       at System.Windows.Forms.Form.OnCreateControl()
       at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
       at System.Windows.Forms.Control.CreateControl()
       at System.Windows.Forms.Control.WmShowWindow(Message&m)
       at System.Windows.Forms.Control.WndProc(Message&m)
       at System.Windows.Forms.ScrollableControl.WndProc(Message&m)
       at System.Windows.Forms.Form.WmShowWindow(Message&m)
       at System.Windows.Forms.Form.WndProc(Message&m)
       at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message&m)
       at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message&m)
       at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
  InnerException: 

以下是实际运行.exe并收到消息时提供的信息:

See the end of this message for details on invoking 
just-in-time (JIT) debugging instead of this dialog box.

************** Exception Text **************
System.IO.IOException: Invalid Signature.

   at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
   at System.IO.FileSystemEnumerableIterator`1.CommonInit()
   at System.IO.FileSystemEnumerableIterator`1..ctor(String path, String originalUserPath, String searchPattern, SearchOption searchOption, SearchResultHandler`1 resultHandler, Boolean checkHost)
   at System.IO.Directory.GetFiles(String path, String searchPattern)
   at Microsoft.VisualBasic.FileIO.FileSystem.FindPaths(FileOrDirectory FileOrDirectory, String directory, String wildCard)
   at Microsoft.VisualBasic.FileIO.FileSystem.FindFilesOrDirectories(FileOrDirectory FileOrDirectory, String directory, SearchOption searchType, String[] wildcards, Collection`1 Results)
   at Microsoft.VisualBasic.FileIO.FileSystem.FindFilesOrDirectories(FileOrDirectory FileOrDirectory, String directory, SearchOption searchType, String[] wildcards)
   at Microsoft.VisualBasic.MyServices.FileSystemProxy.GetFiles(String directory, SearchOption searchType, String[] wildcards)
   at APRS.frmReportViewer.frmReportViewer_Load(Object sender, EventArgs e)
   at System.Windows.Forms.Form.OnLoad(EventArgs e)
   at System.Windows.Forms.Form.OnCreateControl()
   at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
   at System.Windows.Forms.Control.CreateControl()
   at System.Windows.Forms.Control.WmShowWindow(Message&m)
   at System.Windows.Forms.Control.WndProc(Message&m)
   at System.Windows.Forms.ScrollableControl.WndProc(Message&m)
   at System.Windows.Forms.Form.WmShowWindow(Message&m)
   at System.Windows.Forms.Form.WndProc(Message&m)
   at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message&m)
   at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message&m)
   at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)


************** Loaded Assemblies **************
mscorlib
    Assembly Version: 4.0.0.0
    Win32 Version: 4.8.4614.0 built by: NET48REL1LAST_B
    CodeBase: file:///C:/Windows/Microsoft.NET/Framework/v4.0.30319/mscorlib.dll
----------------------------------------
APRS
    Assembly Version: 4.9.0.0
    Win32 Version: 4.9.0.0
    CodeBase: file://hrdc-drhc.net/Sites/NC/ESDC_DSL/RMS%20inbox/SRU%20R85407%20-%20APRS%20Desktop%20v4.9/APRS.exe
----------------------------------------
System.Web.Services
    Assembly Version: 4.0.0.0
    Win32 Version: 4.8.4084.0 built by: NET48REL1
    CodeBase: file:///C:/windows/Microsoft.Net/assembly/GAC_MSIL/System.Web.Services/v4.0_4.0.0.0__b03f5f7f11d50a3a/System.Web.Services.dll
...

我尚未尝试修复此问题,因为我希望在此之前进行研究并在此处咨询。

英文:

I have a clickonce application written in VB in 2015 VS and when someone clicks on the .exe I send them for the first time they get the msg "An Unhandled exception has occurred in your application. If you click continue the application will ignore this error and attempt to continue..."

If the user clicks continue then closes and restarts the application they no longer get this msg. But for how long I dont know. I say that because I managed to see where it is happening in my code after running it multiple times perfectly fine then the odd time.. i see the exception. So its not consistent and is confusing me.

Here is the code that it happens on:

Dim UpfileNames As Object = My.Computer.FileSystem.GetFiles(spath, FileIO.SearchOption.SearchTopLevelOnly, "DR087*.OLD")

spath is a link to a 'share' folder set up in IIS on our network server that is stored as a key
in our web service's web.config file. key="FileLocationSharePath" value="\erdtd4587\DataStorage"

Here is the exception info I get when in VS when the exception actually occurs. Any help is greatly appreciated.



System.IO.IOException was unhandled
  HResult=-2146500602
  Message=Invalid Signature.

  Source=mscorlib
  StackTrace:
       at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
       at System.IO.FileSystemEnumerableIterator`1.CommonInit()
       at System.IO.FileSystemEnumerableIterator`1..ctor(String path, String originalUserPath, String searchPattern, SearchOption searchOption, SearchResultHandler`1 resultHandler, Boolean checkHost)
       at System.IO.Directory.GetFiles(String path, String searchPattern)
       at Microsoft.VisualBasic.FileIO.FileSystem.FindPaths(FileOrDirectory FileOrDirectory, String directory, String wildCard)
       at Microsoft.VisualBasic.FileIO.FileSystem.FindFilesOrDirectories(FileOrDirectory FileOrDirectory, String directory, SearchOption searchType, String[] wildcards, Collection`1 Results)
       at Microsoft.VisualBasic.FileIO.FileSystem.FindFilesOrDirectories(FileOrDirectory FileOrDirectory, String directory, SearchOption searchType, String[] wildcards)
       at Microsoft.VisualBasic.MyServices.FileSystemProxy.GetFiles(String directory, SearchOption searchType, String[] wildcards)
       at APRS.frmReportViewer.frmReportViewer_Load(Object sender, EventArgs e) in C:\Working\APRS-SASR\APRS4.9\APRSApplication\Forms\frmReportViewer.vb:line 29
       at System.Windows.Forms.Form.OnLoad(EventArgs e)
       at System.Windows.Forms.Form.OnCreateControl()
       at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
       at System.Windows.Forms.Control.CreateControl()
       at System.Windows.Forms.Control.WmShowWindow(Message& m)
       at System.Windows.Forms.Control.WndProc(Message& m)
       at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
       at System.Windows.Forms.Form.WmShowWindow(Message& m)
       at System.Windows.Forms.Form.WndProc(Message& m)
       at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
       at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
       at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
  InnerException: 

and here is the info it provides when actually running the exe and getting the msg..

See the end of this message for details on invoking 
just-in-time (JIT) debugging instead of this dialog box.

 

************** Exception Text **************
System.IO.IOException: Invalid Signature.

 

   at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
   at System.IO.FileSystemEnumerableIterator`1.CommonInit()
   at System.IO.FileSystemEnumerableIterator`1..ctor(String path, String originalUserPath, String searchPattern, SearchOption searchOption, SearchResultHandler`1 resultHandler, Boolean checkHost)
   at System.IO.Directory.GetFiles(String path, String searchPattern)
   at Microsoft.VisualBasic.FileIO.FileSystem.FindPaths(FileOrDirectory FileOrDirectory, String directory, String wildCard)
   at Microsoft.VisualBasic.FileIO.FileSystem.FindFilesOrDirectories(FileOrDirectory FileOrDirectory, String directory, SearchOption searchType, String[] wildcards, Collection`1 Results)
   at Microsoft.VisualBasic.FileIO.FileSystem.FindFilesOrDirectories(FileOrDirectory FileOrDirectory, String directory, SearchOption searchType, String[] wildcards)
   at Microsoft.VisualBasic.MyServices.FileSystemProxy.GetFiles(String directory, SearchOption searchType, String[] wildcards)
   at APRS.frmReportViewer.frmReportViewer_Load(Object sender, EventArgs e)
   at System.Windows.Forms.Form.OnLoad(EventArgs e)
   at System.Windows.Forms.Form.OnCreateControl()
   at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
   at System.Windows.Forms.Control.CreateControl()
   at System.Windows.Forms.Control.WmShowWindow(Message& m)
   at System.Windows.Forms.Control.WndProc(Message& m)
   at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
   at System.Windows.Forms.Form.WmShowWindow(Message& m)
   at System.Windows.Forms.Form.WndProc(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
   at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

 


************** Loaded Assemblies **************
mscorlib
    Assembly Version: 4.0.0.0
    Win32 Version: 4.8.4614.0 built by: NET48REL1LAST_B
    CodeBase: file:///C:/Windows/Microsoft.NET/Framework/v4.0.30319/mscorlib.dll
----------------------------------------
APRS
    Assembly Version: 4.9.0.0
    Win32 Version: 4.9.0.0
    CodeBase: file://hrdc-drhc.net/Sites/NC/ESDC_DSL/RMS%20inbox/SRU%20R85407%20-%20APRS%20Desktop%20v4.9/APRS.exe
----------------------------------------
System.Web.Services
    Assembly Version: 4.0.0.0
    Win32 Version: 4.8.4084.0 built by: NET48REL1
    CodeBase: file:///C:/windows/Microsoft.Net/assembly/GAC_MSIL/System.Web.Services/v4.0_4.0.0.0__b03f5f7f11d50a3a/System.Web.Services.dll
----------------------------------------
System
    Assembly Version: 4.0.0.0
    Win32 Version: 4.8.4605.0 built by: NET48REL1LAST_C
    CodeBase: file:///C:/windows/Microsoft.Net/assembly/GAC_MSIL/System/v4.0_4.0.0.0__b77a5c561934e089/System.dll
----------------------------------------
System.Windows.Forms
    Assembly Version: 4.0.0.0
    Win32 Version: 4.8.4550.0 built by: NET48REL1LAST_C
    CodeBase: file:///C:/windows/Microsoft.Net/assembly/GAC_MSIL/System.Windows.Forms/v4.0_4.0.0.0__b77a5c561934e089/System.Windows.Forms.dll
----------------------------------------
System.Drawing
    Assembly Version: 4.0.0.0
    Win32 Version: 4.8.4390.0 built by: NET48REL1LAST_C
    CodeBase: file:///C:/windows/Microsoft.Net/assembly/GAC_MSIL/System.Drawing/v4.0_4.0.0.0__b03f5f7f11d50a3a/System.Drawing.dll
----------------------------------------
System.Data
    Assembly Version: 4.0.0.0
    Win32 Version: 4.8.4584.0 built by: NET48REL1LAST_B
    CodeBase: file:///C:/windows/Microsoft.Net/assembly/GAC_32/System.Data/v4.0_4.0.0.0__b77a5c561934e089/System.Data.dll
----------------------------------------
System.Core
    Assembly Version: 4.0.0.0
    Win32 Version: 4.8.4621.0 built by: NET48REL1LAST_C
    CodeBase: file:///C:/windows/Microsoft.Net/assembly/GAC_MSIL/System.Core/v4.0_4.0.0.0__b77a5c561934e089/System.Core.dll
----------------------------------------
System.Xml
    Assembly Version: 4.0.0.0
    Win32 Version: 4.8.4084.0 built by: NET48REL1
    CodeBase: file:///C:/windows/Microsoft.Net/assembly/GAC_MSIL/System.Xml/v4.0_4.0.0.0__b77a5c561934e089/System.Xml.dll
----------------------------------------
System.Configuration
    Assembly Version: 4.0.0.0
    Win32 Version: 4.8.4190.0 built by: NET48REL1LAST_B
    CodeBase: file:///C:/windows/Microsoft.Net/assembly/GAC_MSIL/System.Configuration/v4.0_4.0.0.0__b03f5f7f11d50a3a/System.Configuration.dll
----------------------------------------
Microsoft.GeneratedCode
    Assembly Version: 1.0.0.0
    Win32 Version: 4.8.4084.0 built by: NET48REL1
    CodeBase: file:///C:/windows/Microsoft.Net/assembly/GAC_MSIL/System.Xml/v4.0_4.0.0.0__b77a5c561934e089/System.Xml.dll
----------------------------------------
Microsoft.VisualBasic
    Assembly Version: 10.0.0.0
    Win32 Version: 14.8.4084.0 built by: NET48REL1
    CodeBase: file:///C:/windows/Microsoft.Net/assembly/GAC_MSIL/Microsoft.VisualBasic/v4.0_10.0.0.0__b03f5f7f11d50a3a/Microsoft.VisualBasic.dll
----------------------------------------
System.Numerics
    Assembly Version: 4.0.0.0
    Win32 Version: 4.8.4084.0 built by: NET48REL1
    CodeBase: file:///C:/windows/Microsoft.Net/assembly/GAC_MSIL/System.Numerics/v4.0_4.0.0.0__b77a5c561934e089/System.Numerics.dll
----------------------------------------

************** JIT Debugging **************
To enable just-in-time (JIT) debugging, the .config file for this
application or computer (machine.config) must have the
jitDebugging value set in the system.windows.forms section.
The application must also be compiled with debugging
enabled.

 

For example:

 

    <configuration>
        <system.windows.forms jitDebugging="true" />
    </configuration>

 

When JIT debugging is enabled, any unhandled exception
will be sent to the JIT debugger registered on the computer
rather than be handled by this dialog box.



I havent tried anything to fix it as I wanted to research it and ask here beforehand.

答案1

得分: 1

如何调试你自己的代码

该函数 FileSystem.GetFiles

Dim UpfileNames As Object = My.Computer.FileSystem.GetFiles(spath, FileIO.SearchOption.SearchTopLevelOnly, "DR087*.OLD")

返回一个 ReadOnlyCollection(Of String),所以你不应将其赋给一个对象。首先,将你的代码更改为:

Dim UpfileNames = My.Computer.FileSystem.GetFiles(spath, FileIO.SearchOption.SearchTopLevelOnly, "DR087*.OLD")

以允许隐式类型转换。现在你将得到一个可以正确使用的东西。

现在针对你的问题,查看 GetFiles(String, SearchOption, String[]) 可能引发的异常:

>异常
><br>ArgumentException
><br>以下原因之一使得路径无效:它是一个零长度的字符串;它只包含空格;它包含无效字符;或者它是设备路径(以 \.\ 开头)。
><br>ArgumentNullException
><br>directory 为 Null。
><br>DirectoryNotFoundException
><br>要搜索的目录不存在。
><br>IOException
><br>目录指向一个现有文件。
><br>PathTooLongException
><br>路径超出了系统定义的最大长度。
><br>NotSupportedException
><br>路径中的文件或目录名称包含冒号(:) 或格式无效。
><br>SecurityException
><br>用户缺少查看路径所需的权限。
><br>UnauthorizedAccessException
><br>用户缺少必要的权限。

检查你的错误消息:

>... ************** 异常文本 **************
<br>System.IO.IOException: 无效的签名。

文档中匹配的异常是:

>IOException
><br>directory 指向一个现有文件。

如果你正在寻找一个目录,目录不应该是一个文件。你应该弄清楚为什么它是一个文件路径而不是一个目录路径(调试你的代码)。为此,请添加一个异常处理程序来处理你所看到的特定异常,并在运行时变量中设置断点和检查。

Try
    Dim UpfileNames = My.Computer.FileSystem.GetFiles(spath, FileIO.SearchOption.SearchTopLevelOnly, &quot;DR087*.OLD&quot;)
Catch ex As System.IO.IOException
    System.Diagnostics.Debug.WriteLine($&quot;&#39;{spath}&#39; 指向一个现有文件 &quot;) &#39; 在此设置断点
End Try
英文:

How To: Debug your own code

That function FileSystem.GetFiles

Dim UpfileNames As Object = My.Computer.FileSystem.GetFiles(spath, FileIO.SearchOption.SearchTopLevelOnly, &quot;DR087*.OLD&quot;)

returns a ReadOnlyCollection(Of String), so you shouldn't assign it to an Object. First of all, change your code to

Dim UpfileNames = My.Computer.FileSystem.GetFiles(spath, FileIO.SearchOption.SearchTopLevelOnly, &quot;DR087*.OLD&quot;)

to allow implicit typing. Now you will have something you can use properly.

Now for your issue, check what exceptions GetFiles(String, SearchOption, String[]) may raise

>Exceptions
><br>ArgumentException
><br>The path is not valid for one of the following reasons: it is a zero-length string; it contains only white space; it contains invalid characters; or it is a device path (starts with \.).
><br>ArgumentNullException
><br>directory is Nothing.
><br>DirectoryNotFoundException
><br>The directory to search does not exist.
><br>IOException
><br>directory points to an existing file.
><br>PathTooLongException
><br>The path exceeds the system-defined maximum length.
><br>NotSupportedException
><br>A file or directory name in the path contains a colon (:) or is in an invalid format.
><br>SecurityException
><br>The user lacks necessary permissions to view the path.
><br>UnauthorizedAccessException
><br>The user lacks necessary permissions.

Checking your error message

>... ************** Exception Text **************
<br>System.IO.IOException: Invalid Signature.

the matching one from the documentation is

>IOException
><br>directory points to an existing file.

Directory shouldn't be a file if you are looking for a directory. You should figure out why it's a file path instead of a directory path (debug your code). To do this, add an exception handler which handles the specific exception you're seeing, and break, and inspect the runtime variables.

Try
    Dim UpfileNames = My.Computer.FileSystem.GetFiles(spath, FileIO.SearchOption.SearchTopLevelOnly, &quot;DR087*.OLD&quot;)
Catch ex As System.IO.IOException
    System.Diagnostics.Debug.WriteLine($&quot;&#39;{spath}&#39; points to an existing file. &quot;) &#39; breakpoint here
End Try

huangapple
  • 本文由 发表于 2023年7月13日 19:51:38
  • 转载请务必保留本文链接:https://go.coder-hub.com/76679067.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定