Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/317.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# AppDomain.CurrentDomain.UnhandledException的处理程序不';我在生产中没有接到电话_C#_Vb.net_Visual Studio 2015_.net 4.6 - Fatal编程技术网

C# AppDomain.CurrentDomain.UnhandledException的处理程序不';我在生产中没有接到电话

C# AppDomain.CurrentDomain.UnhandledException的处理程序不';我在生产中没有接到电话,c#,vb.net,visual-studio-2015,.net-4.6,C#,Vb.net,Visual Studio 2015,.net 4.6,情况如下。Crystal Reports在.net-4.6中遇到一些问题,并在尝试加载crdb_adoplus.dll时抛出异常(System.IO.FileNotFoundException),调用堆栈从CrystalDecisions.ReportAppServer.DataSetConversion.DataSetConverter.DataSetProcessingDelegate,这意味着,我不能把它包在试抓块里。为了至少记录这些问题,有一个AppDomain.CurrentDomai

情况如下。Crystal Reports在.net-4.6中遇到一些问题,并在尝试加载
crdb_adoplus.dll时抛出异常(
System.IO.FileNotFoundException
),调用堆栈从
CrystalDecisions.ReportAppServer.DataSetConversion.DataSetConverter.DataSetProcessingDelegate
,这意味着,我不能把它包在试抓块里。为了至少记录这些问题,有一个
AppDomain.CurrentDomain.UnhandledException
-处理程序被设置为my
Sub Main
中的第一个操作。它可以工作,但是如果我从Visual Studio运行应用程序,它只能工作,如果直接运行应用程序,它就不能工作

另外,我知道如何使Crystal报告工作(
useLegacyV2RuntimeActivationPolicy
),我只是在寻找一种处理此类错误的方法

Update1:这是Windows窗体应用程序和AppDomain.CurrentDomain.UnhandledException
应用程序的两个处理程序,ThreadException
正在运行(后者与
应用程序一起运行。SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException,True)
),但由于某些原因,这个特殊的异常不会发生(但只有在不从VisualStudio启动的情况下…)

子主菜单
如下所示

<STAThread()>
Sub Main()
    AddHandler AppDomain.CurrentDomain.UnhandledException, AddressOf UnhandledThreadExceptionHandler
    Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException, True)

    'many lines of code...

    AddHandler Application.ThreadException, AddressOf ThreadExceptionHandler
    Application.Run(x)
End Sub

这是WPF还是Windows窗体应用程序?您能告诉我们您是如何订阅活动的,以及您在其中做了什么吗?--另外,您是否尝试过设置异常模式:
Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException)?@请参阅Update1@alexw这是Windows窗体(另请参见更新1)
“许多代码行…
是问题所在。加载Crystal时将引发此异常。由即时编译器触发。它需要编译Main()才能开始运行。因此,在到达AddHandler语句之前引发异常。您需要编写另一个方法,并将有风险的代码移入其中。从技术上讲,您应该为它设置[MethodImpl(MethodImplOptions.NoInLine)]属性,但当它这么大时,这不是必需的。这是WPF还是Windows窗体应用程序?您能告诉我们您是如何订阅活动的,以及您在其中做了什么吗?--另外,您是否尝试过设置异常模式:
Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException)?@请参阅Update1@alexw这是Windows窗体(另请参见更新1)
“许多代码行…
是问题所在。加载Crystal时将引发此异常。由即时编译器触发。它需要编译Main()才能开始运行。因此,在到达AddHandler语句之前引发异常。您需要编写另一个方法,并将有风险的代码移入其中。从技术上讲,您应该为它提供[MethodImpl(MethodImplOptions.NoInLine)]属性,但当它这么大时,这不是必需的。
Private wsExNr As Integer = 0

Friend Sub UnhandledThreadExceptionHandler(ByVal sender As Object, ByVal e As UnhandledExceptionEventArgs)
    Dim ex = TryCast(e.ExceptionObject, Exception)

    If ex IsNot Nothing Then
        ex.Data.Add("isUnhandledThreadExceptionHandler", True)
        ex.Data.Add("isMainThread", (Threading.Thread.CurrentThread.ManagedThreadId = wsMainThreadId))
        If sender IsNot Nothing Then
            ex.Data.Add("Sender", sender.GetType.FullName)
        End If
    End If

    Dim path = IO.Path.Combine(My.Computer.FileSystem.SpecialDirectories.Desktop, "Exception_Log")
    IO.Directory.CreateDirectory(path) 'no need in checking if it exists etc -- it's built-in.

    Dim nr = Threading.Interlocked.Increment(wsExNr)
    Dim timestamp_str = ""
    Try
        timestamp_str = Now.ToString("yyyyMMddhhmmss.fff")
    Catch : End Try
    Using wr As New IO.StreamWriter(IO.Path.Combine(path, "ex" & timestamp_str & "_" & nr & ".txt"))
        wr.WriteLine("UnhandledThreadExceptionHandler!")
        If ex IsNot Nothing Then
            wr.WriteLine(ex.ToString)
        End If
    End Using

    If ex IsNot Nothing Then
        If Core.Visual.Dialogs.Internal.MainWindow IsNot Nothing AndAlso Core.Visual.Dialogs.Internal.MainWindow.IsHandleCreated Then
            Core.Visual.Dialogs.Internal.MainWindow.Invoke(New Action(Of Exception)(AddressOf ShowUnhandledThreadException), ex)
        Else
            MsgBox("UnhandledException:" & vbNewLine & ex.ToString)
        End If
    Else
        MsgBox("UnhandledException:" & vbNewLine & e.ExceptionObject.ToString)
    End If
End Sub

Private Sub ShowUnhandledThreadException(ByVal ex As Exception)
    'this is basically a MsgBox
    Core.Visual.Dialogs.ExceptionDialog.Show(
        ex,
        Diagnostics.EventLogEntryType.Error,
        True)
End Sub