Solution #1
If the cause is due to the scoping of the FE API object then the solution would be to make the FE API object modular and change how it is declared and processed. For example (code snippet, not entire code):
'Declaration
Private SC_FE As Blackbaud.PIA.FE7.AFNInterfaces.IBBSessionContext
Private myFEAPI As Blackbaud.PIA.FE7.BBAFNAPI7.FE_API

Private Sub FE_Connection()
 Dim FE_User as String = "XX"
 Dim FE_Password as String = "XX"
 Dim sDBNumber as String = "1"

  myFEAPI = New Blackbaud.PIS.FE7.BBAFNAPI7.FE_API
  Try
    myFEAPI .Init ("XX", FE_User, FE_Password, CInt(sDBNumber), ""XX", Blackbaud.PIA.FE7.BBAFNAPI7.AppMode.amServer)

  Catch ex as Exception
    MessageBox.Show("Error with API_FE.init" & ex.message, "App Name", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
    myFEAPI = Nothing
    Exist Sub
  End Try

  Try
   SC_FE = CType(myFEAPI.SessionContext, Blackbaud.PIA.FE7.AFNInterfaces.IBBSessionContext)

  Catch ex As Exception
   MessageBox.Show("Error with SC_FE = IBBSessionContext" & ex.message, "App Name", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
   myFEAPI = nothing
   Exit Sub
  End Try

End Sub

Public Sub KillAPI()
'This subroutine explicitly cleans up all class-level
'API objects.
Kill_FE_API()
 
  If Not apiValue Is Nothing Then
   Dim sess As BBInterfaces.IBBSessionContext
   sess = DirectCast(apiValue.SessionContext, BBInterfaces.IBBSessionContext)
   While (ReleaseComObject(sess) > 0)
   End While
   sess = Nothing
  End If

  System.GC.Collect()
  System.GC.WaitForPendingFinalizers()
End Sub

Public Sub Kill_FE_API()

  If Not myFEAPI Is Nothing Then
   ReleaseComObject(myFEAPI)
   myFEAPI = Nothing
  End If

End Sub

Solution #2
If the cause is due to garbage collection in .NET and C# for example, create a function that returns an IBBSessionContext object. Here is an example code snippet.

Private Function GetMySessionContext as IBBSessionContext
If <session context object name> is nothing then
                            
'Re-initialize Blackbaud app and grab a session context object

End if

Return <session context object name>

End Function

''And anywhere you are passing in the session context, replace with the above function call (for example):

'Old
Dim oMyBBTopLevelObject as cRecord
Dim oSessionContext as IBBSessionContext

Set oSessionContext = oAPI.SessionContext

Set oMyBBTopLevelObject = new cRecord
oMyBBTopLevelObject.Init oSessionContext

'New
Dim oMyBBTopLevelObject as cRecord
Dim oSessionContext as IBBSessionContext

Set oSessionContext = oAPI.SessionContext

Set oMyBBTopLevelObject = new cRecord
oMyBBTopLevelObject.Init GetMySessionContext

This will accomplish two things:
  1. One can put a breakpoint and track where the object is nothing (one entry point)
  2. It will reset itself
Disclaimer: We provide programming examples for illustration only, without warranty either expressed or implied, including, but not limited to, the implied warranties of merchantability and/or fitness for a particular purpose. This article assumes you are familiar with Microsoft Visual Basic and the tools used to create and debug procedures. Blackbaud Customer Support may help explain the functionality of a particular procedure, but we will not modify, or assist you with modifying, these examples to provide additional functionality.