I have a class bMainframe that manages the connections to 4 different mainframes. It allows for the same underlying unmanaged library to be opened in specific ways and more than one mainframe to be connected to at a time. Each library has its own disposal code for the unmanaged mainframe connection resource. The wrapper also has code that calls the individual mainframe connection's disposal code.
This causes an error if someone's project does not make use of all 4 mainframes, but calls the disposal on the wrapper. (FileLoadException could not load assembly X of the 4 managed mainframes) Since that disposal code checks to see which of the 4 are not nothing/null. Even if nothing/null this is causing .net to try to load the assembly and crash.
Is the disposal code in the outer wrapper helpful or necessary? is there a way to check if the assembly for a type is even loaded that doesn't trigger.net to load the type/assembly?
I modified the code below to block the fileloadexception, but I don't believe this is the best way.
Protected Overridable Sub Dispose(ByVal disposing As Boolean)
If Not Me.disposedValue Then
If disposing Then
' TODO: free managed resources when explicitly called
End If
Try
If Me._Linx IsNot Nothing Then
If _Linx.cnLinx IsNot Nothing Then
Try
_Linx.Disconnect()
Catch ex As Exception
Trace.WriteLine("Error doing linx.disconnectSession")
End Try
Try
_Linx.Dispose()
Catch ex As Exception
Trace.WriteLine("Error doing linx.dispose")
End Try
End If
End If
Catch ex As IO.FileLoadException
Debug.WriteLine("Failed to load LinxFile")
End Try
Try
If Me._Acaps IsNot Nothing Then
_Acaps.Disconnect()
_Acaps.Dispose()
End If
Catch ex As IO.FileLoadException
Debug.WriteLine("Failed to load AcapsFile")
End Try
Try
If Me._Dart IsNot Nothing Then
Try
_Dart.Dispose()
Catch ex As Exception
Trace.WriteLine("Error disposing of Dart")
End Try
End If
Catch ex As IO.FileLoadException
Debug.WriteLine("Failed to load DartFile")
End Try
Try
If LpsOpen Then
Try
_Lps.Dispose()
Catch ex As Exception
Trace.WriteLine("Error disposing of Lps")
End Try
End If
Catch ex As IO.FileLoadException
Debug.WriteLine("Failed to load LpsFile")
End Try
' TODO: free shared unmanaged resources
End If
Me.disposedValue = True
End Sub