控制台应用程序在应用程序中抛出异常但不在调试中

Console application throw exception in application but not in debug

每次在控制台应用程序中抛出异常 运行 这个简单的代码

    Public Function convertWord(ByVal file As String, ByVal Path As String) As Integer

    Dim convertObj As Microsoft.Office.Interop.Word.Application
    Dim WordDoc As Microsoft.Office.Interop.Word.Document

    Try
        convertObj = New Microsoft.Office.Interop.Word.Application
        WordDoc = New Microsoft.Office.Interop.Word.Document
        WordDoc = convertObj.Documents.Open(Path)
        WordDoc.ExportAsFixedFormat(file, WdExportFormat.wdExportFormatPDF)
        Return 2
    Catch ex As Exception
        _checkLog("Originalna greška je : " & ex.Message & ex.StackTrace)
        Return 5
    End Try

End Function

如果我使用调试模式,这个功能就完美了。否则

Log check: 30.12.2015. 11:17:15 Originalna greška je : Object reference not set to an instance of an object. Line 34

Line 34>>>WordDoc = convertObj.Documents.Open(Path)

打开 DCOM 配置设置:

1. Start -> dcomcnfg.exe
2. Computer
3. Local Computer
4. Config DCOM
5. Search for Microsoft Word 97-2003 Documents -> Properties

选项卡标识,从启动用户更改为交互用户。