I maintain a Sql Server database application whose forms are compiled
in a .dll and kept in a remote web folder. The main .exe looks to the
web folder to see if this .dll exists. If so, then it compares the
..dll with the cache copy. If the cache copy is older then it downloads
a new copy. If the .dll is not present, it throws an error.
In my main .exe, I need to early bind my "Main" form from my
FormsLibrary.dll to get data into it. If I run my application by
loading the .dll from my local /bin folder, it works. When I run the
application by loading the .dll from the web folder, it fails, saying
there was a Cast Exception. The two .dlls are synonymous because I
copy the .dll from my local directory to the web folder.
Still, there is a version conflict.
How do I resolve this cast problem?
My code follows:
Try
Dim MyPermission As New
Permissions.FileIOPermission(Security.Permissions. PermissionState.Unrestricted)
MyPermission.Demand()
'download assembly from a web server over HTTP
Dim sLocation As String
sLocation = "HTTP://gabriel/ems/FormsLibrary.dll"
Dim formAsm As [Assembly] = [Assembly].LoadFrom(sLocation)
'get the form from the assembly
Dim formType As Type
formType = formAsm.GetType("FormsLibrary.frmMain")
'create an instance of the form
Dim formObj As Object
formObj = Activator.CreateInstance(formType)
'cast it to a form object to enable early binding and show
the form
**** LINE BELOW THROWS EXCEPTION WHEN REFERRING TO WEB FOLDER
..DLL
'FormsLibrary is my remote .dll
Dim frmMain As FormsLibrary.frmMain = CType(formObj,
FormsLibrary.frmMain)
frmMain.FormsLibraryVersion =
formAsm.GetName.Version.ToString
frmMain.ShowDialog()
Catch exc As Exception
Throw exc
End Try