Dynamic Reference

  • Thread starter Thread starter Derek Hart
  • Start date Start date
D

Derek Hart

I have a commercial product that I built using VB.NET windows forms.
Different clients have different references that need to be set to other
products. Some of the references are local references, and some are web
references. How can I make these references dynamically load at runtime?
How could I store a URL in the database (Microsoft SQL Server) and have it
build the references the first time the program loads, and on subsequent
loads detect that the reference is already there?

This brings up another issue. I have code that directly refers to these
references? How could I also conditionally compile the code so it only is
seen at runtime based whether or not the reference is there?

Any specific code or direction would be much appreciated.

Thank You,
Derek Hart
 
Hi Derek,

Based on my understanding now, you don't want to reference an assembly at
design-time and want to load it in runtime.
..NET Runtime has several methods to Load an Assembly at runtime.
You may read the following article to see how to load an assembly at
runtime.
<How the Runtime Locates Assemblies>
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/htm
l/cpconhowruntimelocatesassemblies.asp

For WebReference, I'm not an expert on this field, but it seems that VS.NET
IDE generate the proxy class at design-time, if you just want to change the
URL of the proxy class you may take a look at this google thread:

http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&oe=UTF-8&threadm=eLnRrql2
BHA.1984%40tkmsftngp02&rnum=9&prev=/groups%3Fhl%3Den%26lr%3D%26ie%3DUTF-8%26
oe%3DUTF-8%26q%3D.NET%2Bcreate%2BWebReference%2Bdynamically

Hope it helps!

Best regards,

Ying-Shen Yu [MSFT]
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security

This posting is provided "AS IS" with no warranties and confers no rights.
This mail should not be replied directly, "online" should be removed before
sending.
 
For the last question: How could I also conditionally compile the code so
it only is
seen at runtime based whether or not the reference is there?

I think you could check the return value of the Assembly.Load to determine
which code should be executed.

Best regards,

Ying-Shen Yu [MSFT]
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security

This posting is provided "AS IS" with no warranties and confers no rights.
This mail should not be replied directly, "online" should be removed before
sending.
 
Back
Top