You are viewing limited content. For full access, please sign in.

Question

Question

Getting an error 9084 when using SDK

asked on April 22, 2014 Show version history

 Good Morning All,

 

I'm using the SDK and Visual Basic Studio 2013 to search for entries that have pre-determined field values for  fields Case Number and Review Number. I followed the advice and suggestions in a previous post. and I'm placing my code at the bottom of this question.

 

My issue is that I am not getting any config errors from VB, but when the code runs it returns an error 9084. Unfortunately I cant use a track token as this process is being run from an externally created VB program using the RA programming settings.

 

The basic process for this evolution is that the user is able to take a csv or txt file and put in the following parameters.

1. Type of Export (PDF or TIF)

2. Case Number

3. Review Number

4. Path to export to

 

A typical row in the text file might look like this:

PDF, 123456789CN, 987654321RN, C:\Mypath

 

The program reads the file (It does this perfectly) then looks through the repository using the parameters:    "{[]:[Case Number]=currentrow(1), [Review Number]=currentrow(2)} & {LF:Name=""*"", Type=""DB""}"

 

It then will create a PDF or TIF export of the document and then place it in the folder path.

 

When I run the debug it throws the error.

 

Best Regards,

Brian

 

 

*************************Code **************

Using myreader As New Microsoft.VisualBasic.FileIO.TextFieldParser("c:\1234.txt")
            myreader.TextFieldType = Microsoft.VisualBasic.FileIO.FieldType.Delimited
            myreader.Delimiters = New String() {",", "\n"}
            Dim currentrow As String()
            While Not myreader.EndOfData
                currentrow = myreader.ReadFields()
                MessageBox.Show(currentrow(0) & " Is the Doc type for this row")
                'currentrow(0) is the Document type (PDF, TIF)
                'currentrow(1) is the Case Number
                'currentrow(2) is the Review number
                'currentrow(3) is the path to place the file
                For Each currentfield In currentrow
                    ' *******************
                    ' *
                    ' *   PDF
                    ' *
                    ' ******************
                    If currentrow(0) = "PDF" Then
                        Try
                            'MessageBox.Show(currentrow(0) & " Made it through the PDF Eval. This is a " & currentrow(0) & "." & " I am supposed to put my stuff in folder " & currentrow(3))
                            ' Set up the variables needed to run the process
                            Dim serverName As String = CMBLaserficheServerName.Text, repositoryName As String = CMBRepositoryName.Text
                            Dim userName As String = CMBLaserficheRepositoryUserLogin.Text, userPassword As String = CMBLaserficheRepositoryUserPassword.Text
                            Dim mySession As New Session
                            Dim listing As New List(Of String)
                            ' Logging into the Repository
                            mySession.LogIn(userName, userPassword, New RepositoryRegistration(serverName, repositoryName))
                           Dim searchParameters As String = "{[]:[Case Number]=currentrow(1), [Review Number]=currentrow(2)} & {LF:Name=""*"", Type=""DB""}"
                            Dim lfSearch As Search = New Search(mySession, searchParameters)
                            Dim settings As SearchListingSettings = New SearchListingSettings
                            Dim searchResults As SearchResultListing
                            ' **  Dim targetFolder As String
                            Dim filePathAndName As String
                            ' What columns do you want the search to retrieve...
                            settings.AddColumn(SystemColumn.Name)
                            settings.AddColumn(SystemColumn.CreationDate)
                            settings.AddColumn(SystemColumn.EntryType)
                            settings.AddColumn(SystemColumn.Path)
                            settings.AddColumn(fieldName:="Review Number")
                            settings.AddColumn(fieldName:="Case Number")
                            ' Have set up search parameters
                            ' Run the search...
                            lfSearch.Run()
                            ' Searching the Repository for items that meet search criteria.
                            ' Get the results...
                            searchResults = lfSearch.GetResultListing(settings)
                            ' If there are any results then step through them...
                            ' 42120141600 If searchResults.RowCount > 0 Then
                            ' 42120141600 For i As Integer = 1 To 1 'searchResults.RowCount
                            ' Verifying directory
                            ' Create the 'root directory from the textbox value...
                            ' ** targetFolder = currentrow(3) & "\" & searchResults.GetDatumAsString(i, SystemColumn.Path)
                            filePathAndName = currentrow(3) & "\" & searchResults.GetDatumAsString(1, SystemColumn.Name) & ".pdf"
                            ' MessageBox.Show("This is supposed to be a " & currentrow(0) & "and is to be placed in " & currentrow(3))
                            VerifyDirectory(currentrow(3))
                            ' Step through the search results and create the subfolders in the root directory above...
                            ' ** VerifyDirectory(targetFolder)
                            ' Creating folder for this item.
                            'currentrow(0) is the Document type (PDF, TIF)
                            'currentrow(1) is the Case Number
                            'currentrow(2) is the Review number
                            'currentrow(3) is the path to place the file
                            'settings.AddColumn(fieldName:="Review Number")
                            'settings.AddColumn(fieldName:="Case Number")
                            If currentrow(1) = settings.AddColumn(fieldName:="Case Number") Then
                                Dim docInfo As DocumentInfo
                                Dim docexporter As New DocumentExporter
                                ' Creating PDF for this iteration  / loop.
                                'Get a reference to the appropriate document...
                                ' getting doc name, ID, and accessing my repository session
                                docInfo = Document.GetDocumentInfo(searchResults.GetDatum(1, SystemColumn.Id), mySession)
                                ' Checking to be sure the PDF has pages and text.
                                If docInfo.AllPages.GetTotalPageCount > 0 Then
                                    ' Setting up the export. Document namne, PDF options (I want the text)
                                    docexporter.ExportPdf(docInfo, docInfo.AllPages, PdfExportOptions.IncludeText, filePathAndName)
                                    ' Small elay to stop COM error
                                    delay(3)
                                    ' PDF was fine so I created it!
                                End If
                            End If
                            ' 42120141600 Next
                            ' 42120141600 End If
                            ' MessageBox.Show("I think I'm done with Row 1 since it was set up to be PDF")
                            'Cleanup...
                            listing = Nothing
                            lfSearch = Nothing
                            settings = Nothing
                            searchResults = Nothing
                            mySession.Close()
                            mySession = Nothing
                        Catch ex As Exception
                            MessageBox.Show(ex.Message)
                        End Try
                    End If
           End While
        End Using
        MessageBox.Show("ok")

 

0 0

Answer

SELECTED ANSWER
replied on April 22, 2014

No need to open a technical support case. Your original search syntax was incorrect, but you have fixed it in your new search string.

 

I have edited your original post to put your code within a code block. Please use the "Code" button in the text editor when posting code, especially long segments like this one. The monospace font and syntax highlighting make it easier for others to read.

 

Your current error of "a string cant be Boolean" is caused by

If currentrow(1) = settings.AddColumn(fieldName:="Case Number")

The call to settings.AddColumn returns a Boolean, but currentrow(1) is a string. You'll probably want to change that to

If currentrow(1) = searchResults.GetDatumAsString(1, "Case Number")

Though it is difficult to tell exactly what you're trying to do there, and this would be superfluous since the search already is only returning objects that have currentrow(1) in the "Case Number" field.

 

A few other things to note:

 

  1. Your comments seem to acknowledge this, but your code will only handle one search result and won't loop through multiple results (and will throw exceptions if there are no search results!).
  2. Your call to Document.GetDocumentInfo will likely cause you some problems unless you cast the result of searchResults.GetDatum to an Integer
  3. I'm not sure why you have a delay after the call to docexporter.ExportPdf. If you are getting an error without the delay, there is likely something else going on and you should try to find a way to fix the underlying error instead.
  4. You don't call dispose on your docInfo object. The best way to do this would be with a Using statement.
  5. Lastly, you are potentially leaking resources by not guaranteeing a call to Dispose on your Session, Search, and SearchResultListing objects. All of these objects implement IDisposable. Any time that you use an object that implements IDisposable, you should guarantee that Dispose is called on it when it is no longer needed. This should be done either by specifying a Finally block or declaring the IDisposable objects in a Using block. 
2 0

Replies

replied on April 22, 2014

changed my search variable to

Dim searchParameters As String = "{[]:[Review Number]=""" & currentrow(2) & """, [Case Number]=""" & currentrow(1) & """} & {LF:Name=""*"", Type=""DB""}"

 

Error is now saying a string cant be Boolean. Any suggestions ?

0 0
replied on April 22, 2014

Please open a case with Laserfiche Support. 9084 means that the search term is invalid. Start a Laserfiche Server trace with only the "Search" event class selected. Then recreate the issue with your application. Stop the Laserfiche Server trace and provide us with the .etl file. That way we can see exactly what search syntax your application is sending to the Laserfiche Server.

0 0
replied on April 23, 2014

Good Morning Everyone,

 

This is the updated code. It is working perfectly in my sandbox running VB NET Studio 2013.using the debug process. The folders are being created correctly, the correct documents are exporting  properly into the correct folders, etc..

 

I complied and ran the setup and application and it also is working perfectly in my sandbox. The folders are being created correctly, the correct documents are exporting  properly into the correct folders, etc..

 

When I install and test in the live environment, I'm not getting any errors, the folders DO create properly, but they remain empty. I am using the same documents, the same data file, etc.

 

I am not getting any file export from the Repository. I have made changed that I understand based on the previous comments, and even cleaned up a few things as unnecessary.

 

A review and opinion of what is going wrong would be appreciated. I've attached the full code for the process including the data file that is being read to pull the items.

 

There is a template that has 2 fields "Case Number" and "Review Number". The template name doesn't matter as I am only concerned with the fields.

 

The process that should be occurring is:

1. Application reads the .txt file, row by row

2. Depending on whether currentrow (0) (the current doc type to export) is set as PDF or TIF, the same process will be run except for the different requirements for a TIF vs a PDF.

3. The chosen path will search the repository and return the results that equal the currentrow(1) (Case Number) and the currentrow(2) (Review Number).

4. Based on the currentrow(0) a  file with the proper type is exported to a path supplied by Currentrow(3) (The path).

5. Everything repeats until there are no more rows of data.

6. Application notifies user of completion and closes down all sessions and activities.

 

Regards,

Brian 

 

    Private Sub BTNRunExport_Click(sender As Object, e As EventArgs) Handles BTNRunExport.Click

        Using myreader As New Microsoft.VisualBasic.FileIO.TextFieldParser("c:\1234.txt")
            myreader.TextFieldType = Microsoft.VisualBasic.FileIO.FieldType.Delimited
            myreader.Delimiters = New String() {",", "\n"}
            Dim currentrow As String()
            While Not myreader.EndOfData
                currentrow = myreader.ReadFields()

                'currentrow(0) is the Document type (PDF, TIF) 
                'currentrow(1) is the Case Number 
                'currentrow(2) is the Review number 
                'currentrow(3) is the path to place the file 
                For Each currentfield In currentrow

                    If currentrow(0) = "PDF" Then
                        Try
                            ' Set up the variables needed to run the process 
                            Dim serverName As String = CMBLaserficheServerName.Text, repositoryName As String = CMBRepositoryName.Text
                            Dim userName As String = CMBLaserficheRepositoryUserLogin.Text, userPassword As String = CMBLaserficheRepositoryUserPassword.Text
                            Dim mySession As New Session
                            Dim listing As New List(Of String)

                            ' Logging into the Repository 
                            mySession.LogIn(userName, userPassword, New RepositoryRegistration(serverName, repositoryName))

                            ' Setting up Search parameters
                            Dim searchParameters As String = "{[]:[Review Number]=""" & currentrow(2) & """, [Case Number]=""" & currentrow(1) & """} & {LF:Name=""*"", Type=""DB""}"
                            Dim lfSearch As Search = New Search(mySession, searchParameters)
                            Dim settings As SearchListingSettings = New SearchListingSettings
                            Dim searchResults As SearchResultListing
                            Dim filePathAndName As String

                            ' What columns do you want the search to retrieve... 
                            settings.AddColumn(SystemColumn.Name)
                            settings.AddColumn(SystemColumn.CreationDate)
                            settings.AddColumn(SystemColumn.EntryType)
                            settings.AddColumn(SystemColumn.Path)
                            settings.AddColumn(SystemColumn.Id) ' added 4/23/2014
                            settings.AddColumn(fieldName:="Review Number")
                            settings.AddColumn(fieldName:="Case Number")

                            ' Run the search. 
                            lfSearch.Run()

                            ' Get the results... 
                            searchResults = lfSearch.GetResultListing(settings)

                            ' If there are any results then step through them... 
                            If searchResults.RowCount > 0 Then
                                For i As Integer = 0 To 1 'searchResults.RowCount 
                                    Dim targetfolder As String
                                    targetfolder = currentrow(3)
                                    filePathAndName = currentrow(3) & "\" & searchResults.GetDatumAsString(1, SystemColumn.Name) & ".pdf"
                                    VerifyDirectory(currentrow(3))
                                    VerifyDirectory(targetfolder)

                                    'currentrow(0) is the Document type (PDF, TIF) 
                                    'currentrow(1) is the Case Number 
                                    'currentrow(2) is the Review number 
                                    'currentrow(3) is the path to place the file 
                                    'settings.AddColumn(fieldName:="Review Number") 
                                    'settings.AddColumn(fieldName:="Case Number") 
                                    If currentrow(1) = searchResults.GetDatumAsString(1, "Case Number") Or currentrow(2) = searchResults.GetDatumAsString(1, "Review Number") Then
                                        Dim docInfo As DocumentInfo
                                        Dim docexporter As New DocumentExporter
                                        ' Creating PDF for this iteration  / loop. 
                                        'Get a reference to the appropriate document... 
                                        ' getting doc name, ID, and accessing my repository session 
                                        docInfo = Document.GetDocumentInfo(searchResults.GetDatum(1, SystemColumn.Id), mySession)
                                        ' Checking to be sure the PDF has pages and text. 
                                        If docInfo.AllPages.GetTotalPageCount > 0 Then
                                            ' Setting up the export. Document namne, PDF options (I want the text) 
                                            docexporter.ExportPdf(docInfo, docInfo.AllPages, PdfExportOptions.IncludeText, filePathAndName)
                                            ' Small elay to stop COM error 
                                            ' delay(3)
                                            ' PDF was fine so I created it! 
                                        End If
                                    End If
                                Next
                            End If
                            'Cleanup... 
                            listing = Nothing
                            lfSearch.Close()
                            lfSearch = Nothing
                            settings = Nothing
                            searchResults = Nothing
                            mySession.LogOut()
                            mySession.Close()
                            mySession = Nothing
                        Catch ex As Exception
                            MessageBox.Show(ex.Message)
                        End Try
                    End If


                    If currentrow(0) = "TIF" Then
                        Try
                            ' Set up the variables needed to run the process
                            Dim serverName As String = CMBLaserficheServerName.Text, repositoryName As String = CMBRepositoryName.Text
                            Dim userName As String = CMBLaserficheRepositoryUserLogin.Text, userPassword As String = CMBLaserficheRepositoryUserPassword.Text
                            Dim mySession As New Session
                            Dim listing As New List(Of String)

                            ' Logging into the Repository
                            mySession.LogIn(userName, userPassword, New RepositoryRegistration(serverName, repositoryName))


                            ' Setting up search parameters
                            Dim searchParameters As String = "{[]:[Review Number]=""" & currentrow(2) & """, [Case Number]=""" & currentrow(1) & """} & {LF:Name=""*"", Type=""DB""}"
                            Dim lfSearch As Search = New Search(mySession, searchParameters)
                            Dim settings As SearchListingSettings = New SearchListingSettings
                            Dim searchResults As SearchResultListing
                            Dim filePathAndName As String

                            ' What columns do you want the search to retrieve...
                            settings.AddColumn(SystemColumn.Name)
                            settings.AddColumn(SystemColumn.CreationDate)
                            settings.AddColumn(SystemColumn.EntryType)
                            settings.AddColumn(SystemColumn.Path)
                            settings.AddColumn(SystemColumn.Id) ' Added 4/23/2014
                            settings.AddColumn(fieldName:="Review Number")
                            settings.AddColumn(fieldName:="Case Number")

                            ' Run the search...
                            lfSearch.Run()

                            ' Get the results...
                            searchResults = lfSearch.GetResultListing(settings)

                            ' If there are any results then step through them...
                            If searchResults.RowCount > 0 Then
                                For i As Integer = 0 To 1 ' searchResults.RowCount
                                    ' Verifying directory
                                    ' Create the 'root directory from the textbox value...
                                    Dim targetfolder As String
                                    targetfolder = currentrow(3)
                                    filePathAndName = currentrow(3) & "\" & searchResults.GetDatumAsString(1, SystemColumn.Name) & ".tif"
                                    VerifyDirectory(currentrow(3))
                                    VerifyDirectory(targetfolder)

                                    'currentrow(0) is the Document type (PDF, TIF) 
                                    'currentrow(1) is the Case Number 
                                    'currentrow(2) is the Review number 
                                    'currentrow(3) is the path to place the file 
                                    'settings.AddColumn(fieldName:="Review Number") 
                                    'settings.AddColumn(fieldName:="Case Number") 
                                    If currentrow(1) = searchResults.GetDatumAsString(1, "Case Number") Or currentrow(2) = searchResults.GetDatumAsString(1, "Review Number") Then
                                        Dim docInfo As DocumentInfo
                                        Dim docexporter As New DocumentExporter

                                        ' Export Configuration settings
                                        docexporter.PageFormat = DocumentPageFormat.Tiff
                                        docexporter.IncludeAnnotations = True
                                        docexporter.BlackoutRedactions = True
                                        'Get a reference to the appropriate document...
                                        ' getting doc name, ID, and accessing my repository session
                                        docInfo = Document.GetDocumentInfo(searchResults.GetDatum(1, SystemColumn.Id), mySession)
                                        ' Checking to be sure the Tif has pages and text.
                                        If docInfo.AllPages.GetTotalPageCount > 0 Then
                                            ' Setting up the export. 

                                            docexporter.ExportPages(docInfo, docInfo.AllPages, filePathAndName)
                                            ' TIF was fine so I created it!
                                            'Only export if the document contains pages OTW the TIFF export will throw an error...
                                            'TIFF...
                                            'small delay to stop a COM error
                                            ' delay(3)
                                        End If
                                    End If
                                Next
                            End If
                            'Cleanup...
                            listing = Nothing
                            lfSearch.Close()
                            lfSearch = Nothing
                            settings = Nothing
                            searchResults = Nothing
                            mySession.LogOut()
                            mySession.Close()
                            mySession = Nothing
                        Catch ex As Exception
                            MessageBox.Show(ex.Message)
                        End Try
                    End If
                Next
            End While
        End Using
        MessageBox.Show("Done with Export!")
    End Sub
Private Sub VerifyDirectory(ByVal folderPath As String)
    If Not Directory.Exists(folderPath) Then
        Directory.CreateDirectory(folderPath)
    End If
End Sub
Private Sub FrmMain_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        CMBLaserficheServerName.Text = "Server name"
        CMBRepositoryName.Text = "Repository Name"
    CMBLaserficheRepositoryUserLogin.Text = "User Name"
    CMBLaserficheRepositoryUserPassword.Text = "Password"
End Sub

 

1234.txt (109 B)
0 0
replied on April 23, 2014

If it works in your sandbox, then the issue is probably something with how your code is interacting with your environment. What are the differences between your sandbox environment and your live environment (i.e. different LF Servers, different host machines, etc.)?

0 0
replied on April 23, 2014

Hi Mathew,

 

I guess you could say Everything is different, and yet some things are the same.

 

Example:

Sandbox - VM Virtual machine running Windows 7 Pro Sp1 x64

Client - Windows Server 2008  Standard

 

Sandbox - LF Client 9.1.1.486

Client - LF Client 9.1.1.486

 

Sandbox -  SDK 9.1.1 x64

Client -  SDK 9.1.1 x64

 

etc, etc.

 

The thing that is throwing me is that if it were an issue with the SDK version, procedure calls etc., then I would expect that the program would not be creating the proper folders as that is the last step prior to creation / export of the document type.

0 0
replied on April 23, 2014

Caveat: I've tried with a Windows 8 machine with the same issue and results

0 0
replied on April 23, 2014

Are you connecting to the Laserfiche Server in both instances? And can you post an example of some of the paths you are trying to write to?

0 0
replied on April 24, 2014

Good Morning Mathew,

 

Yes sir, in all cases I am connecting to the respective server.

 

For my Sandbox the Server is Laserfiche-svr. For the Client's site it is SysMed02

 

The paths that I have attempted to write to are: C:\GotThePDF, C:\GotTheTif.

 

I have also tried going a level deeper C:\testme\GoTThePDF for example.

 

The whole process seems to work fine except that it is not exporting PDF or TIF. I also have checked to be sure the LF Documents have pages associated and are not empty as that is a "stop" condition.

 

 Regards,

Brian

 

P.S. Should I continue this thread in a new thread specifically about doc export issues as we've cleared up the original issue?

 

Thanks!

0 0
replied on April 24, 2014

Question,

 

I installed the SDK Runtime library on the client server whereas I have the SDK full kit. Are there any settings and such that must be part of the setup on a client that does not have an SDK license? Could this be why the program only partly works? Meaning that the non Repository search / export functions appear to be working but not the actual file export ?

 

Regards,

Brian

0 0
replied on April 24, 2014

Since your original question has been answered, please post a new question specifically about your DocumentExporter issues. Include in the post the details of your two environments, as well as a few relevant snippets of your code (by relevant I mean that we don't need to see your search code if it is just the export code not working).

 

Please also remember to mark whichever answer answered your original question as the Accepted Answer so anyone searching for this issue in the future can find it easily.

 

Before you post, I'd recommend that you confirm that the account you are using in the Client's environment has the appropriate rights to export from the repository.

1 0
replied on April 23, 2014

Good Morning Mathew,

 

I looked over your comments and made some changes and I'll explain my thoughts to your questions.

 

 

1. Your comments seem to acknowledge this, but your code will only handle one search result and won't loop through multiple results (and will throw exceptions if there are no search results!).

 

I only wanted the process to handle known items, one row at a time based on a supplied list of documents to pull. (They are always supposed to be there)

 

 

2. Your call to Document.GetDocumentInfo will likely cause you some problems unless you cast the result of searchResults.GetDatum to an Integer

 

I took your advice and made the change you showed in the code.

 

 

3. I'm not sure why you have a delay after the call to docexporter.ExportPdf. If you are getting an error without the delay, there is likely something else going on and you should try to find a way to fix the underlying error instead.

 

The delay was removed as unneeded. When the original code was designed it was looking for multiple iterations and when the client decided they were going to provide a list, I no longer had the problem of the process moving too fast.

 

4. You don't call dispose on your docInfo object. The best way to do this would be with a Using statement.

 

I'm not sure I understand how to use the using statement as you are describing. I thought it would be enough to simply close and dispose of the instances. Can you provide more explanation please ?

 

5. Lastly, you are potentially leaking resources by not guaranteeing a call to Dispose on your Session, Search, and SearchResultListing objects. All of these objects implement IDisposable. Any time that you use an object that implements IDisposable, you should guarantee that Dispose is called on it when it is no longer needed. This should be done either by specifying a Finally block or declaring the IDisposable objects in a Using block. 

 

Same as 4, but I have modified my code to "dispose" of the objects now. I hope I did it correctly.

 

Best Regards,

Brian

0 0
replied on April 23, 2014 Show version history

In regards to your question about the "Using" statement, I'll have to go into a tiny bit of background:

 

In the .Net world, there are two kinds of resources: managed and unmanaged. Managed resources are easy - the garbage collector will automatically and intelligently get rid of them when you no longer need them. Unmanaged resources are tricky - they represent things allocated without the knowledge of the garbage collector, so it can't clean them up!

 

There are two things that help to deal with managed resources: Finalizers and the Dispose pattern. Finalizers are a method that the garbage collector will call on a managed resource to allow it to get rid of any unmanaged resources that it knows about. The Dispose pattern allows user code to tell an object that it no longer needs its unmanaged resources, so it should clean them up right now.

 

The garbage collector will call the Finalizer on your objects eventually, but there are two problems with allowing the Finalizer to take care of disposal of unmanaged resources. First, the garbage collector is non-deterministic. This means that it will eventually call the Finalizer, but you don't know when. It is nice to know when the file that you have open will actually be closed so that other processes can use it instead of waiting indefinitely for the Finalizer to be called. The other problem is that when the Garbage Collector calls the Finalizer, the object no longer knows whether the objects that it has reference to exist anymore - the Garbage Collector may have already destroyed them! This means that the object cannot necessarily guarantee that all of its umanaged resources get cleaned up.

 

When managed resources fail to get cleaned up, it is a leak. Leaks are bad for a variety of reasons, so it is imperative that we avoid them. So we should use the Dispose pattern whenever it is provided by a class that we use. The problem is, what if an Exception is thrown before we are able to call Dispose? That exception might be handled somewhere and the application might continue, and we would have failed to call Dispose resulting in a leak!

 

The solution is to always remember to call Dispose in a Finally block. Finally blocks will always execute (unless the computer no longer has power). This gives us the nice guarantee that Dispose will always be called.

 

The downside is that Finally blocks are big and not fun to write out. I'd much rather just tell the runtime that I'd like this object to be Disposed in a Finally block and let the compiler figure it out. Enter the Using statement. You already have one in your code. Basically, the Using statement tells the compiler just that: Declare these variables here, and at the end of this block put a Finally that Disposes of them.

 

Here's how it looks:

Using s As New Session
    ' Do stuff with s!
End Using
' s has had Dispose called on it in a Finally block!

That's much more succinct than a Try-Finally!

 

Note that it is especially important to Dispose of objects provided by RepositoryAccess when they implement IDisposable. Those objects don't just represent resources on your computer, but resources on the server, so when you leak them you are actually leaking them on your Laserfiche Server!

 

More information on Using can be found here.

 

More information on the Dispose pattern can be found here (examples in C# but the idea applies to VB.Net as well).

1 0
You are not allowed to follow up in this post.

Sign in to reply to this post.