Click here to Skip to main content
15,887,596 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
I'm trying to get my application to load the dll references that it needs to run from another folder such as C:\ so that the exe can be moved without the need to keep its dlls in the same directory. Please help!
Posted
Comments
Toli Cuturicu 6-Dec-10 3:39am    
Absurd idea! Don't do it!

Just so you can move the exe is not a valid reason for this design. .NET can use xcopy deployment so moving the folder, with exe and assemblies, is no problem.

How the Runtime Locates Assemblies[^]

Locating the Assembly through Codebases or Probing[^]
 
Share this answer
 
Comments
halodu03de 5-Dec-10 22:21pm    
=/ just because you don't think it's valid reason doesn't mean it isn't.
[no name] 6-Dec-10 0:06am    
Years more experience than you says it isn't a good idea.
TO Get All Information from DLL
C#
Assembly assembly = Assembly.LoadFrom(@"C:\Program Files (x86)\Common Files\microsoft shared\DevServer\10.0\Additionsusersandip0.dll");
            Type[] t = assembly.GetTypes();
            foreach (Type tt in t)
            {
                if (tt.IsClass) Console.WriteLine("Name space is = " + tt.Namespace);
                MethodInfo[] mi = tt.GetMethods();
                Console.WriteLine(mi.ToString());
                foreach (MethodInfo methodinfo in mi)
                {
                    ParameterInfo[] pi = methodinfo.GetParameters();
                    Console.WriteLine(methodinfo.Name);
                    Console.WriteLine(methodinfo.ReturnType.ToString());
                    Console.WriteLine(methodinfo.ReturnParameter.ParameterType.ToString());
                    foreach (ParameterInfo p in pi)
                    {
                        p.GetType();
                        Console.WriteLine(p.Name);
                        Console.WriteLine(p.ParameterType);
                    }
                }
            }


To Invoke the DLL Method

C#
Assembly myAssem = Assembly.LoadFile(strFullDummyDLLFilePath);
            Type[] t = myAssem.GetTypes();
            foreach (Type type in t)
            {
                // Invoke Method if the type is class only
                if (type.IsClass)
                {
                    // Load an assembly file into an object.
                    Object objAssembly = Activator.CreateInstance(type);
                    object[] objInputParams = null;
                    objResult = type.InvokeMember(strMethodName, BindingFlags.InvokeMethod,null, objAssembly, new Object[] { objIPParameters });   
                 }
            }
 
Share this answer
 
Comments
[no name] 6-Dec-10 0:09am    
Hard coded paths? Seriously? So you can use reflection to get information about an assembly or invoke a method. How does this help solve the OP's problem? Should he rewrite the application to call all methods through reflection?
sandipapatel 6-Dec-10 1:15am    
Hey, only the pathofdll is hardcoded. Due my mistake i didn't remove it. But reflection is the only way in the universe to invoke dll methods resides outside the project folder.
Thanks for voting & showing my mistake.
No boarders for improvement
[no name] 6-Dec-10 9:00am    
No reflection is not the only way to handle this situation. Read the response links and learn.
sandipapatel 6-Dec-10 10:01am    
Hi, Mark I want to know the other options of dynamically loading dll and invoke its method at runtime.
As per you said please send me the idea or link for doing so.
Due I am currently in R&D dept. in our university & really wanted to do this stuff before a month ago. So, please send me the needful that I can improve my code
[no name] 7-Dec-10 19:01pm    
Read the first answer.

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