Spire.PDF is a professional PDF library applied to creating, writing, editing, handling and reading PDF files without any external dependencies. Get free and professional technical support for Spire.PDF for .NET, Java, Android, C++, Python.

Tue Apr 29, 2014 10:33 am

hi, I get the following error when generating a doc.

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

derek
 
Posts: 42
Joined: Mon Nov 19, 2012 11:55 am

Wed Apr 30, 2014 2:51 am

Hello,

To help us reproduce the error, would you please provide us your documents? Thanks.

Best wishes,
Amy
User avatar

amy.zhao
 
Posts: 2766
Joined: Wed Jun 27, 2012 8:50 am

Return to Spire.PDF