Loading remote assembly throws Cast Exception

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Brent

    #1

    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.dl l 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.Fil eIOPermission(S ecurity.Permiss ions.Permission State.Unrestric ted)

    MyPermission.De mand()

    'download assembly from a web server over HTTP
    Dim sLocation As String
    sLocation = "HTTP://gabriel/ems/FormsLibrary.dl l"

    Dim formAsm As [Assembly] = [Assembly].LoadFrom(sLoca tion)

    '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.Creat eInstance(formT ype)

    '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.fr mMain = CType(formObj,
    FormsLibrary.fr mMain)

    frmMain.FormsLi braryVersion =
    formAsm.GetName .Version.ToStri ng

    frmMain.ShowDia log()
    Catch exc As Exception
    Throw exc
    End Try
Working...