I have an application that is referencing a dll that will keep changing to a newer version (with backwards compatibility).
My app (built in visual studio 2015) will work with any version - the problem is - i need to reference the dll without specifying the version bec the latest version dll will constantly be replacing the dll in my project (office requirements) and i dont want to recompile my project every time the dll is updated
I tried the following:
setting <AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
in my .csproj file
AppDomain.CurrentDomain.AssemblyResolve += delegate (object s, ResolveEventArgs re) { AssemblyName theName = new AssemblyName(re.Name); if (theName.Name == "name, version, key") { return Assembly.LoadFile("name without version"); } return null; };
im not really sure where to put the second thing that i tried but nothing seems to be working!!
solved it one way - but im still looking for a better answer -
i created a class from the assembly by loading my dll
like -
Assembly assemblyInstance=Assembly.Load(dll);
Type[] asseblyTypes=assemblyInstance.GetTypes();
foreach(Type t in asseblyTypes)
{
if(t.fullName.Equals(name of class i want))
{
try to get the method info by t.GetMethod(name,type of parameter)
and then do methodInfo.Invoke...
}
}
works... but id like a better answer
A neater way would be using the AssemblyResolve event -
Something like the following:
AppDomain.CurrentDomain.AssemblyResolve += (sender, argsAssembly) =>
{
if (argsAssembly.Name.StartsWith the name of your dll)
return Assembly.Load(load the dll);
return null;
};
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.