0

I have seen a few similar questions, but I hope this is not quite a duplicate. I am using the FO.NET project found here: https://fonet.codeplex.com/ to generate PDF files from within my VB.NET application.

The Fonet.dll and Fonet.exe files are both included with the application, and I am calling it like so:

Public Sub FormatObjectToPdf(intRxNo As Integer, strSourceFileName As String)
    Dim startInfo As New ProcessStartInfo
    Dim strPdfFile As String = StrRootPath & "Paperwork\" & intRxNo & "M.pdf"

    ' if the PDF file already exists, no need to re-create it
    If Not File.Exists(strPdfFile) Then
        Try
            startInfo.Arguments = "-fo """ & strSourceFileName & """ -pdf """ & strPdfFile & """"
            startInfo.FileName = StrAppPath & "FO.NET\fonet.exe"
            startInfo.UseShellExecute = True
            startInfo.WindowStyle = ProcessWindowStyle.Hidden

            Using proc As Process = Process.Start(startInfo)
                proc.WaitForExit()

                If proc.HasExited Then
                    proc.Dispose()
                End If
            End Using
        Catch ex As Exception
            Call InsertLog("ErrorLog", "FormatObjectToPdf: " & ex.Message, ex)
            MessageBox.Show(ex.Message, "Create PDF", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
        End Try
    End If

    ' wait 3 seconds to allow file to be released
    Threading.Thread.Sleep(3000)

    ' delete the source FO file when processing is complete
    If File.Exists(strSourceFileName) Then
        Try
            File.Delete(strSourceFileName)
        Catch iEx As IOException
            Call InsertLog("ErrorLog", "[IOException]: Could Not delete file '" & strSourceFileName & "': " & iEx.Message)
        Catch ex As Exception
            Call InsertLog("ErrorLog", "Error deleting file '" & strSourceFileName & "': " & ex.Message, ex)
        End Try
    End If
End Sub

My problem is that occasionally the process will fail, and an unhandled exception will popup and the Fonet.exe application will crash (not the calling application). If I re-run the exact same call, it usually works. It is only happening occasionally, but it seems to be increasingly frequent. Is there a way to catch the exception from the external program for debugging? Or some other way to see what is causing it to crash, so that I can try to fix it?

dub stylee
  • 3,252
  • 5
  • 38
  • 59
  • Have you checked Windows's Event Viewer? It can usually reveal some information. If you find a log for CLR20r3, then read [**this**](http://stackoverflow.com/questions/4052770/deciphering-the-net-clr20r3-exception-parameters-p1-p10). – Visual Vincent Nov 18 '16 at 23:00
  • I added the project as a reference and am calling the functions from within my application rather than using `ProcessStartInfo`, hopefully that will help me track down the error. – dub stylee Nov 19 '16 at 00:47
  • Hey, Visual Studio has a debugging tool, Debug>Attach to Process – conquistador Nov 19 '16 at 08:19
  • @conquistador that would be nice if it were on my development machine that the problem occurs... unfortunately everyone doesn't have Visual Studio installed – dub stylee Nov 21 '16 at 17:05

0 Answers0