System.NullReferenceException was unhandled
Message="Object reference not set to an instance of an object."
Source="mscorlib"
StackTrace:
at System.Collections.Generic.ObjectEqualityComparer`1.IndexOf(T[] array, T value, Int32 startIndex, Int32 count)
at System.Array.IndexOf[T](T[] array, T value, Int32 startIndex, Int32 count)
at System.Collections.Generic.List`1.IndexOf(T item)
at System.Collections.Generic.List`1.Remove(T item)
at .ᜄ( A_0)
at Spire.Pdf.Graphics.PdfTrueTypeFont.Dispose()
at Spire.Pdf.Graphics.PdfTrueTypeFont.Finalize()
InnerException:
and sometimes this:
System.IndexOutOfRangeException was unhandled
Message="Index was outside the bounds of the array."
Source="mscorlib"
StackTrace:
at System.Collections.Generic.List`1.RemoveAt(Int32 index)
at System.Collections.Generic.List`1.Remove(T item)
at .ᜀ(List`1 A_0)
at .ᜄ( A_0)
at Spire.Pdf.Graphics.PdfTrueTypeFont.Dispose()
at Spire.Pdf.Graphics.PdfTrueTypeFont.Finalize()
InnerException:
Any ideas? the code is below thanks.
- Code: Select all
Public Shared Function CreateLetter(ByVal sLetterName As String, ByVal sReportId As String, ByVal sCreditors As String, ByVal sApplicationPath As String) As String
Dim iUserId As Integer = Entities.Users.UserController.GetCurrentUserInfo.UserID
Dim sSQL As String
Dim dsLetters As New DataSet
Dim sFullLetter As String
Dim letterPath = String.Empty
sCreditors = sCreditors.Remove(0, 1)
sSQL = "SP_PRINT_GROUPED_lETTERS '" + sCreditors.Remove(sCreditors.Length - 1, 1) + "'," + sReportId + "," + CStr(iUserId)
sSQL = sSQL.Replace(Chr(34), " '")
dsLetters = ReturnDataSet(sSQL)
Spire.License.LicenseProvider.ClearLicense()
Spire.License.LicenseProvider.SetLicenseFileName("license.elic.xml")
Try
If dsLetters IsNot Nothing Then
Dim dt As DataTable = ReturnDataTable(sSQL)
'get template
Dim sTemplateFile = dt.Rows(0)("TemplateFileName").ToString()
If sTemplateFile.Length < 1 Then
sTemplateFile = GetTemplateDoc()
End If
Dim document As New Document(sApplicationPath + "Desktopmodules\AnnualReport\Uploads\" + CStr(iUserId) + "\" + sTemplateFile)
AddHandler document.MailMerge.MergeImageField, AddressOf DoMergeImage
document.MailMerge.Execute(dt)
sFullLetter = "\" + sLetterName + CStr(iUserId) + CStr(Now().Year) + CStr(Now().Month) + CStr(Now().Day) + CStr(Now().Minute) + CStr(Now().Second) + ".pdf"
letterPath = sApplicationPath + "Desktopmodules\AnnualReport\Uploads\" + CStr(iUserId) + sFullLetter
document.SaveToFile(letterPath, FileFormat.PDF)
document = Nothing
End If
Catch ex As Exception
'Response.Write(ex.Message)
Finally
End Try
Return letterPath
End Function