To change the path that references an assembly, see https://learn.microsoft.com/en-us/dotnet/framework/configure-apps/specify-assembly-location.
Use LoadLibrary to switch to a native dll at runtime.
using System;
using System.IO;
using System.Runtime.InteropServices;
internal class Program
{
static Program() {
var pathToDll = Environment.Is64BitProcess ? @".\x64" : @".\x86";
LoadLibrary(Path.Combine(pathToDll, "YourNative.dll"));
}
[DllImport("kernel32", SetLastError = true, CharSet = CharSet.Auto)]
static extern IntPtr LoadLibrary(string lpFileName);
[DllImport("YourNative.dll")]
internal static extern IntPtr YourNativeFunction();
static void Main(string[] args) {
Console.WriteLine($"{YourNativeFunction()}");
Console.ReadKey();
}
}