I'm trying to use reflection to load assemblies that are exes. The objective is to provide a harness that loads all the infrastructure, which is made up of various resources that are data, data access and utilities. The reason for this is the load time to is up to 90 seconds to 120 seconds for the entire infrastructure. So rather than have different instances of the infrastructure one is spinned up and shared for all. Each exe uses that infrastructure and through reflection in a service the infrastructure is injected into the exe. All fine when it's done the first time. The problem I'm having is that when I'm making changes in the exe's code and re-compile and then try to reload the new assembly using Assembly.LoadFrom method, it always loads the first assembly not the new one. So obviously the service caches the first assembly and everytime I try to reload with a new one it uses the older one. I'm on .net 4.8
Any Ideas?
public static dynamic CreateObjectFromAssembly(string assemblyLocation, string type, object[] parameters)
{
Assembly sampleAssembly = null;
AssemblyAccessor.LoadAssembly(assemblyLocation, ref sampleAssembly);
return CreateObjectFromAssembly(sampleAssembly, type, parameters);
}
public static dynamic CreateObjectFromAssembly(Assembly sampleAssembly, string type, object[] parameters)
{
dynamic result = null;
if (sampleAssembly != null)
{
Type foundOne = sampleAssembly.GetTypes().Where(x => x.FullName.Equals(type)).FirstOrDefault();
if (parameters == null)
result = Activator.CreateInstance(foundOne);
else
result = Activator.CreateInstance(foundOne, parameters);
}
return result;
}
public static void LoadAssembly(String assemblyLocation, ref Assembly SampleAssembly)
{
try
{
SampleAssembly = Assembly.LoadFrom(assemblyLocation);
}
catch(Exception e)
{
}
}
Aucun commentaire:
Enregistrer un commentaire