471,075 Members | 724 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,075 software developers and data experts.

Loading remote assembly throws Cast Exception

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
Jul 21 '05 #1
0 1774

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Kent Rollins | last post: by
4 posts views Thread by Aashish Patil | last post: by
6 posts views Thread by Pete Davis | last post: by
5 posts views Thread by RickN | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.