问题描述:

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

网友答案:

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.

网友答案:

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.

网友答案:

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.)

网友答案:

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).

网友答案:

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!

相关阅读:
Top