Maybe I can add something new. Unless I missed something (possible!) in these many posts, there doesn't appear to be an accepted solution or any mention of System.Reflection.Assembly.LoadFrom(filename) which is the method .NET provides when you need explicit control. If the Modules tab shows assemblies loading from unexpected locations, this is how you can fix that and get your debug breaks back.
Sometimes there are very good reasons for doing this. For me, it was when I was supporting a platform that allowed users to create somewhat arbitrary plug-ins, and I had to be careful about having a race with those plugins about where the common assemblies get loaded from. The goal was to make sure the "golden" versions living in the same directory as my Platform.exe would ALWAYS be the ones to load without exception. (Putting them in the GAC is sometimes the right answer but not always).
I has been rightly mentioned in other posts that default build settings cause referenced assemblies to get copied locally in the \bin of the plug in when it builds. Plug-ins are one example of a use case where that's the total opposite of what you want to happen. There might be 100 users with 100 plugins and 100 copies of a given assembly. Which one of the 100 will load? And will it be the latest, correct version?
Here's how I was able to do this reliably for a real-world platform that I supported for more than a decade, loading assemblies up-front.
using System;
using System.ComponentModel;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Windows.Forms;
[STAThread]
static void Main()
{
PreLoadAssemblies();
Form appInstance = new InstanceManager();
Application.Run(appInstance);
}
private static void PreLoadAssemblies()
{
// Obtain an explicit folder path relative to where
// the main executable ("Platform.exe") is running.
string dir =
Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) +
@"\Accessories\PlugIn\google-drive-sync\netstandard2.0";
PreLoadAssembly(dir, "Google.Apis.Auth.dll");
PreLoadAssembly(dir, "Google.Apis.Drive.v3.dll");
PreLoadAssembly(dir, "Google.Apis.Auth.PlatformServices.dll");
PreLoadAssembly(dir, "Google.Apis.dll");
PreLoadAssembly(dir, "Google.Apis.Core.dll");
PreLoadAssembly(dir, "Google.Apis.PlatformServices.dll");
PreLoadAssembly(dir, "Newtonsoft.Json.v10.dll");
}
private static void PreLoadAssembly(string dir, string name)
{
try
{
Assembly resolved = Assembly.LoadFrom(dir + @"\" + name);
Debug.Assert(resolved != null);
}
catch (Exception ex)
{
Debug.Assert(false, ex.Message);
}
}