By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
428,530 Members | 891 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 428,530 IT Pros & Developers. It's quick & easy.

Loading Assemblies or Classes in C#

P: 81
Hey All,
I posted something similar in the .NET forums, but am unsure where it belongs, so forgive me if this is the wrong place.

I have a client application, and a folder containing dll's that the application will need to use. In java, if I put jars in the classpath, the JVM loads them automatically.

Is there something similar in .NET or am I stuck calling Assembly.Load on all the dll's in the folder?

Dec 17 '08 #1
Share this Question
Share on Google+
2 Replies

Expert Mod 5K+
P: 9,731
I have a feeling that you're stuck calling the Load() method for each assembly that you want to load dynamically.

If you don't need to load the assemblies dynamically you could just add a reference to the assemblies to your application.

Have you tried any of the other solution ideas offered in your other thread?

Since this question is about assemblies rather than C#, I would have said your question belongs in the .NET forum; however, since your implementation will be in C# I'm going to leave your thread here.

Dec 18 '08 #2

Expert 100+
P: 190
This is a common issue, where developers have some directory that stores their dlls and want their applications to reference that directory.
Assembly.Load is not really your answer, because when you compile your application, the compiler needs all the metadata of referenced libraries in order to use any of their methods. So when you compile, you would need to reference the dlls anyways, and the reference process makes a copy of the library in your local output directory.
The CLR documentation clearly stipulates:
At run time, a reference must exist in either the Global Assembly Cache (GAC) or the output path of the project.
Dynamically loading and unloading assemblies is an odd construct of Reflection. From an application standpoint, even if you got it to work, I would not recommend it as the solution just so that you can reference a common library. I believe its intent is geared towards memory management and the ability for a process to load/unload an (already referenced) assembly to/from memory as needed.

Is this just for one client, or for an application that will be distributed? If distributed, that gets complex, so I won't list all the scenarios here.

If just for one client, I would recommend one of two options (the GAC option was already posted)
- export your common library to the GAC.
- in your project, add the path to your common library to the Project properties: How to: Set the Reference Path (C# , J#) - It will still copy those dlls to your output directory on each compile, but it will always retrieve the latest version from that common directory on each compile.
Dec 19 '08 #3

Post your reply

Sign in to post your reply or Sign up for a free account.