Loading and Unloading .dll file in C#
-
Hi, how can I load and unload a .dll file at runtime in my C# project. I need urgent reply plz help me. thankx
How do you need to load it? Do you need to read it or use it, if you need to use the .dll then there would be no point in unloading it.
-
Hi, how can I load and unload a .dll file at runtime in my C# project. I need urgent reply plz help me. thankx
http://www.c-sharpcorner.com/2/pr12.asp does this help?
-
http://www.c-sharpcorner.com/2/pr12.asp does this help?
thanks for u r help, actually i am doing the same thing as mentioned in www.c-sharpcorner.com/2/pr12.asp, through this way i have to explicitly add the .dll file (component)to my project(using add reference),but i want to add(load) that component at runtime. as we do in VC++.
-
thanks for u r help, actually i am doing the same thing as mentioned in www.c-sharpcorner.com/2/pr12.asp, through this way i have to explicitly add the .dll file (component)to my project(using add reference),but i want to add(load) that component at runtime. as we do in VC++.
pakfari: Use Assembly to load the dll, like so: Assembly SampleAssembly; string fullp = ((Full Path to the dll)) SampleAssembly = Assembly.LoadFrom(fullp); //In order to create an Instance of it you have to grab the type of this class //use Namespace.ClassName Type ObjType = SampleAssembly.GetType(Namespace.ClassName); //Create an instance of your dll here Activator.CreateInstance(ObjType); As far as running the Dll, there are a few ways to do it. but this is how you would/could load it at runtime. Hope his helps Steve Welborn Software Architect
-
pakfari: Use Assembly to load the dll, like so: Assembly SampleAssembly; string fullp = ((Full Path to the dll)) SampleAssembly = Assembly.LoadFrom(fullp); //In order to create an Instance of it you have to grab the type of this class //use Namespace.ClassName Type ObjType = SampleAssembly.GetType(Namespace.ClassName); //Create an instance of your dll here Activator.CreateInstance(ObjType); As far as running the Dll, there are a few ways to do it. but this is how you would/could load it at runtime. Hope his helps Steve Welborn Software Architect
-
I will just say Great!!! It is working ok, can u tell me one more thing. How we can invoke the member functions of the Component using objType.
Well, this is where it can get tricky..at least for me. Because there are a few ways to do this, depending on if you want to call the function right then, or place that object in a Collections class and call it later. Hopefully someone will be able to explain it better than I can, but here goes. This is how I executed a .dll after loading it. Remember that when you created the Instance it passed back an object object instance; //what Assembly.CreateInstance returns object[] args; //Parameters to pass the function MethodInfo method = type.GetMethod(functionname); object returnval = method.Invoke(instance, args); I hope this helps. Steve Welborn Software Architect