title: C# load a dll from file, then update that dll and then re-load the dll from file
body: <p>tldr; I need to be able to reference a dll, update the dll and then reference the new dll</p>
  
  <p>We have a service that takes weeks to update on our production system, and one use case that will require an update cycle of less than a day, our solution to this is to have the system load .dll files directly into itself and then use the classes/methods from those assemblies. The problem is that I can only seem to reference the first dll, any attempt at using a new one gets ignored. </p>
  
  <p>The Functional code I have is </p>
  
  <pre><code>Assembly myAssembly1 = Assembly.LoadFrom("path.dll");
  Type myType = myAssembly1.GetType("ClassName");
  var myObject = Activator.CreateInstance(myType);
  dynamic test = myType.InvokeMember("methodName", BindingFlags.InvokeMethod, null, myObject, null);
  await test;
  </code></pre>
  
  <p>This method get's referenced a few times, and apparently the the first 'LoadFrom' is the only one that actually changes the app domain. </p>
  
  <p>I understand creating a new App domain each time will solve the issue, but I can't seem to get it to work; </p>
  
  <pre><code>AppDomain domain = AppDomain.CreateDomain("MyDomain");
  Assembly myAssembly1 = domain.Load(AssemblyName.GetAssemblyName(path));
  //or = domain.Load(path);
  //or = domain.Load("assemblyname");
  Type myType = myAssembly1.GetType("ClassName");
  var myObject = Activator.CreateInstance(myType);
  dynamic test = myType.InvokeMember("methodName", BindingFlags.InvokeMethod, null, myObject, null);
  await test;
  AppDomain.Unload(domain);
  </code></pre>
  
  <p>So far any attempt at loading the .dll file into my app domain has resulted in the error 'Error: Could not load file or assembly 'assemblyName, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified.', I'm assuming this is either me not putting the .dll file in the right location, or not handling the dependencies properly. </p>
  
  <p>Any help would be greatly appreciated, I keep trying different things and seem to keep running into walls</p>
  
  <p>thanks in advance</p>
  
  <p>Cuan</p>
  
  <p>Edit:
  windows 10, .net standard 2.0</p>