Hi all!
I was wondering if there is a way to get location of assemby rather than specifying it directly at Assembly.Load(...), can we use Assembly.Load and inside the parameter, we extract the probing path from app.config?
app.config:
<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<probing privatePath="version_control;version2;bin2\subbin;bin3"/>
<dependentAssembly>
<assemblyIdentity name="myAssembly" publicKeyToken="1524dba369a4decc"/>
<bindingRedirect oldVersion="1.0.0.0" newVersion="2.0.0.0"/>
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
Now C# file:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Reflection;
namespace MainProgram
{
class Program
{
static void Main(string[] args)
{
//TODO! I WANT TO HAVE A PROBING PATH ON MY "findDLL", is it possible? HOW? :-)
Assembly findDLL = Assembly.Load("myAssembly"); // use this not LoadFile, then you will need absolutepath
Type customerType = findDLL.GetType("myAssembly.Customer");
object cuInstance = Activator.CreateInstance(customerType);
MethodInfo getFullNameMethod = customerType.GetMethod("getFullName");
string[] param = new string[2];
param[0] = "Khiem";
param[1]= "Ho Xuan";
//invvoke method
string fname = (string)getFullNameMethod.Invoke(cuInstance, param);
Console.WriteLine(fname);
}
}
}
//class library file for .dll
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace myAssembly
{
public class Customer
{
public string getFullName(string first, string last)
{
return "Check " + first + " last " + last;
}
}
}
THANKS!