代码运行时不会出现错误,直到出现“向 Microsoft 发送错误报告”为止。出现
我有一些 vb.net 代码,应该使用 Teklynx LabelView 软件(我之前已经工作过)打印标签。
问题是,它在开发计算机上运行良好,但当我在最终用户的 PC 上运行它时,我不'不会收到任何错误消息,直到它完全消失并显示“将错误报告发送给 Microsoft”消息。
我该如何解决这个问题???
相关代码:
Shared Function PrintLabels(ByVal itemDescription As String, ByVal starting As String, ByVal ending As String, ByVal qty As Integer) As Boolean
'Create "Document" (Label) object
'Close all open lv.exe processes
Dim pProcess() As Process = System.Diagnostics.Process.GetProcessesByName("lv")
For Each p As Process In pProcess
p.Kill()
Next
Dim Lbl As Object
Lbl = CreateObject("Lblvw.Document")
Lbl.Open(labelFileName)
Dim barcodeVal As String
Dim labelText As String
Try
Dim infoArray As String()
infoArray = itemDescription.Split(New Char() {","c})
labelText = infoArray(1).ToString().Trim()
barcodeVal = infoArray(2).Trim() & starting & ending
'Load label in ReadOnly mode
Lbl.Open(labelFileName, True)
'Get field information
Dim Flds As Object
Flds = Lbl.LabelFields
Flds.Item("TEXT1").Value = labelText
Flds.Item("BARCODE1").Value = barcodeVal
Lbl.PrintLabel(qty)
Lbl = Nothing
barcodeVal = Nothing
labelText = Nothing
Return True
Catch ex As Exception
If printStatements Then
MsgBox("Error Message: " & ex.Message.ToString())
End If
Using writer As New StreamWriter(errorLog, True)
writer.AutoFlush = True
writer.WriteLine()
writer.WriteLine(DateTime.Now.ToString() & ": " & ex.Message)
End Using
Lbl = Nothing
barcodeVal = Nothing
labelText = Nothing
Return False
End Try
End Function
I have some vb.net code which should print out labels using Teklynx LabelView software (which I've had working before.)
Problem is, it runs fine on Dev machine, but when I run it on the end user's PC, I don't get any error messages until it completely dies with the "Send error report to Microsoft" message.
How can I troubleshoot this???
Relevant code:
Shared Function PrintLabels(ByVal itemDescription As String, ByVal starting As String, ByVal ending As String, ByVal qty As Integer) As Boolean
'Create "Document" (Label) object
'Close all open lv.exe processes
Dim pProcess() As Process = System.Diagnostics.Process.GetProcessesByName("lv")
For Each p As Process In pProcess
p.Kill()
Next
Dim Lbl As Object
Lbl = CreateObject("Lblvw.Document")
Lbl.Open(labelFileName)
Dim barcodeVal As String
Dim labelText As String
Try
Dim infoArray As String()
infoArray = itemDescription.Split(New Char() {","c})
labelText = infoArray(1).ToString().Trim()
barcodeVal = infoArray(2).Trim() & starting & ending
'Load label in ReadOnly mode
Lbl.Open(labelFileName, True)
'Get field information
Dim Flds As Object
Flds = Lbl.LabelFields
Flds.Item("TEXT1").Value = labelText
Flds.Item("BARCODE1").Value = barcodeVal
Lbl.PrintLabel(qty)
Lbl = Nothing
barcodeVal = Nothing
labelText = Nothing
Return True
Catch ex As Exception
If printStatements Then
MsgBox("Error Message: " & ex.Message.ToString())
End If
Using writer As New StreamWriter(errorLog, True)
writer.AutoFlush = True
writer.WriteLine()
writer.WriteLine(DateTime.Now.ToString() & ": " & ex.Message)
End Using
Lbl = Nothing
barcodeVal = Nothing
labelText = Nothing
Return False
End Try
End Function
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
检查您正在构建的 .NET 版本以及客户端计算机上拥有的 .NET 版本。
如果用户使用的 .NET 版本较低,则您正在使用的某些内容可能无法与用户向后兼容。
Check what version of .NET you are building to and what version of .NET the client has on their machine.
Something you are using might not be back compatible with the user if the user has a lesser version of .NET.
这个就别猜了实现 AppDomain.CurrentDomain.UnhandledException 事件并记录或显示 e.ExceptionObject.ToString() 的值。它准确地告诉您出了什么问题,并通过堆栈跟踪向您展示错误是如何产生的。
Don't guess at this. Implement the AppDomain.CurrentDomain.UnhandledException event and log or display the value of e.ExceptionObject.ToString(). It tells you exactly what went wrong, with a stack trace to show you how to wrongness came to be.
除了 @Jack 提到的 .NET 版本之外,还要注意 32 位与 64 位。如果标签软件仅针对 32 位构建,则当您在 Visual Studio 中以“任何 CPU”为目标并且在 64 位计算机上运行该程序时,您的程序将无法运行。在这种情况下,CLR 将编译为 64 位,然后将无法链接到 32 位库。 (但是在不了解该软件的情况下,我不知道这是否对您有影响。)
In addition to the .NET version as @Jack mentions, be aware of 32-bit vs 64-bit. If the label software is built for 32-bit only, your program won't run if you're targeting "Any CPU" in Visual Studio and you're running it on a 64-bit machine. In this case, the CLR will compile to 64-bit and then won't be able to link to the 32-bit library. (But without knowing the software, I don't know if this is affecting you.)
听起来您必须正确安装 Teklynx LabelView 组件。如果它是一个 COM 组件(您确实用“OLE”标记了这个问题并且您正在使用 CreateObject),则它将需要一个注册表项。复制并粘贴 bin\ 将不起作用。 Teklynx 文档对重新分发组件有何说明?我从来没有必要在 .NET 中注册 COM 组件...只有在 VB6 中,安装程序和组件才需要注册。部署向导已处理。为了进行测试,请找到一台干净的客户端 PC 并使用 regsrv32.exe 手动注册 Teklynx .DLL。
Sounds like you have to properly install the Teklynx LabelView component. If it's a COM component (you did tag this question with "OLE" and you are using CreateObject), it'll require a registry entry. Copying and pasting the bin\ won't work. What does the Teklynx documentation say about redistributing the component? I've never had to register a COM component in .NET ... only back in VB6 which the Setup & Deployment Wizard handled. For testing, find a clean client PC and use regsrv32.exe to manually register the Teklynx .DLL(s).
看起来它是 Teklynx LabelView 软件的不同版本。该代码以前在 v7 Gold 版本上运行,但在某些时候它升级到 v8.5 Pro 版本,该版本不支持 OLE 自动化。查看升级到黄金版以确认这确实是问题所在。
更新:是的,这就是问题所在。谢谢大家!
Looks like its a different version of the Teklynx LabelView software. This code worked previously on v7 Gold edition, but at some point it was upgraded to v8.5 Pro edition, which does not support OLE Automation. Looking at upgrading to Gold to confirm that this is indeed the problem.
UPDATE: Yes, this was the problem. Thanks all!