add reference programmatically

G

Gary Brewer

Hi,

I have a Windows Forms application stub (Admin.exe) that runs on a local
machine. It loads assemblies from a website programmatically using the
Assembly.LoadFrom 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.LoadFrom 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
 
G

Gary Brewer

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=AppDomain.CurrentDomain;

domain.AssemblyResolve+=new System.ResolveEventHandler(reh);


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

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

foreach(Assembly assembly in AppDomain.CurrentDomain.GetAssemblies())
{

if(assembly.FullName.StartsWith(rea.Name.Split(new
char[]{','})[0])) return assembly;

}

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

return null;

}





Is this the only way around this?



Regards,



Gary
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top