Click here to Skip to main content
15,885,366 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hi Everybody,

I need some help for the following issue.

I have created a windows control in VB.net and saved as dll file.

I need to show this control in a windows form by loading this file.

How can I acheive this.

Thanks
P A S Saravanan.
Posted

You simply add a reference to the DLL in your project.

http://msdn.microsoft.com/en-us/library/wkze6zky(v=vs.80).aspx[^]
 
Share this answer
 
Comments
Sandeep Mewara 16-May-11 10:25am    
Comment from OP:
Thanks for your info.

But I need to do this step without adding any reference.

Meaning I need to add this control dynamically at the run time.

Thanks
P A S Saravanan
Sergey Alexandrovich Kryukov 16-May-11 21:00pm    
Understood. Please see my answer -- it contains all you need to know to accomplish exactly that.
--SA
I provided very detailed skeleton of the design required to consume assemblies during run-time.

Please see my past answers:
Create WPF Application that uses Reloadable Plugins...[^],
AppDomain refuses to load an assembly[^].

It may look overly complex, but don't worry: you probably don't need to solve most complex problems related to unloadable plug-ins and hence Application Domain. Ignore all this.

You only need to develop plug-in interface, the system to recognize its implementation class in the loaded library and invocation of the constructor via Reflection.

—SA
 
Share this answer
 
You can use Reflection to access a DLL during runtime, something like this:

C#
Assembly asm = Assembly.Load("myclasslibrary.dll");
from there you can access the Classes and Methods in that DLL, using methods like asm.GetTypes() or asm.GetType("yourclass"). Here is the MSDN article on Reflection[^].

Good Luck
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 16-May-11 20:55pm    
Wayne, Don't mislead OP. Did you do it yourself? I think you did not -- it won't work! Assembly.Load does not do what you think.
Must be Assembly.LoadFrom. GetType("yourclass") is a really bad method of doing plug-in, as it relies on hard-coded name. The robust way is based on using interface; then no assumptions are done beyond compiled declaration.
--SA
Sergey Alexandrovich Kryukov 16-May-11 20:59pm    
Please see my answer -- it's comprehensive.
--SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900