add reference programmatically

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

    #1

    add reference programmatically

    Hi,

    I have a Windows Forms application stub (Admin.exe) that runs on a local
    machine. It loads assemblies from a website programmaticall y using the
    Assembly.LoadFr om static method.

    One of the assemblies it loads is called RTC.dll, which, in the VS.NET
    designer has a reference to RTCremoting.DLL , which it uses to perform
    remoting of some sorts.

    RTCremoting.DLL is basically

    public interface IMyInt {
    MyObject myMethod();
    }

    [Serializable]
    public class MyObject {
    string a, b;
    }




    When I use the remoting channel that is setup in RTC.dll I get a 'Cannot
    find assembly RTCremoting' error message. If I change my return type for
    myMethod to, say, a string there is no issue.

    To resolve the problem, I had to do an 'Add Reference' on my Admin.exe to
    RTCremoting.DLL in the VS.NET designer. However, I do not want to load it
    this early, I want to get the RTCremoting.DLL from a remote location when
    the Admin.exe loads.

    Doing Assembly.LoadFr om on RTCremoting.DLL does not solve the problem. I
    need to somehow reference this assembly to the executing assembly (i think)
    and I have no idea how to do this. Any help would be appreciated.


    Regards,

    Gary Brewer









  • Gary Brewer

    #2
    Re: add reference programmaticall y

    I have come up with an intermediate solution, I am sure this is not the best
    way to do it, but kudos to Bruce Brown.

    AppDomain domain=AppDomai n.CurrentDomain ;

    domain.Assembly Resolve+=new System.ResolveE ventHandler(reh );


    static public Assembly reh(object o, System.ResolveE ventArgs rea) {

    if(rea.Name.ToU pper().IndexOf( "RESOURCES")>=0 ) return null;

    foreach(Assembl y assembly in AppDomain.Curre ntDomain.GetAss emblies())
    {

    if(assembly.Ful lName.StartsWit h(rea.Name.Spli t(new
    char[]{','})[0])) return assembly;

    }

    MessageBox.Show ("Couldn't find " + rea.Name);

    return null;

    }





    Is this the only way around this?



    Regards,



    Gary




    "Gary Brewer" <gary@fathand.c om> wrote in message
    news:%23L3wRAuS DHA.1664@TK2MSF TNGP11.phx.gbl. ..[color=blue]
    > Hi,
    >
    > I have a Windows Forms application stub (Admin.exe) that runs on a local
    > machine. It loads assemblies from a website programmaticall y using the
    > Assembly.LoadFr om static method.
    >
    > One of the assemblies it loads is called RTC.dll, which, in the VS.NET
    > designer has a reference to RTCremoting.DLL , which it uses to perform
    > remoting of some sorts.
    >
    > RTCremoting.DLL is basically
    >
    > public interface IMyInt {
    > MyObject myMethod();
    > }
    >
    > [Serializable]
    > public class MyObject {
    > string a, b;
    > }
    >
    >
    >
    >
    > When I use the remoting channel that is setup in RTC.dll I get a 'Cannot
    > find assembly RTCremoting' error message. If I change my return type for
    > myMethod to, say, a string there is no issue.
    >
    > To resolve the problem, I had to do an 'Add Reference' on my Admin.exe to
    > RTCremoting.DLL in the VS.NET designer. However, I do not want to load it
    > this early, I want to get the RTCremoting.DLL from a remote location when
    > the Admin.exe loads.
    >
    > Doing Assembly.LoadFr om on RTCremoting.DLL does not solve the problem. I
    > need to somehow reference this assembly to the executing assembly (i[/color]
    think)[color=blue]
    > and I have no idea how to do this. Any help would be appreciated.
    >
    >
    > Regards,
    >
    > Gary Brewer
    >
    >
    >
    >
    >
    >
    >
    >
    >[/color]


    Comment

    Working...