To clarify, I set up what I thought was a simple test, but if I made a glaring error another set of eyes always helps. I created a deployment which looks like this:
And here's the code for App.xaml.cs:
using Esri.ArcGISRuntime;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Runtime.Loader;
using System.Threading.Tasks;
using System.Windows;
namespace DeploymentTest
{
/// <summary>
/// Interaction logic for App.xaml
/// </summary>
public partial class App : Application
{
private static IntPtr runtimeLibPtr = IntPtr.Zero;
private static IntPtr runtimeLibWpfPtr = IntPtr.Zero;
private const string DeploymentHome = @"C:\apps";
private const string RuntimeVersion = "100.12";
private static string NativeInstallPath;
private static string DLLversion;
private void Application_Startup(object sender, StartupEventArgs e)
{
try
{
string sRuntimeDeployment = "ArcGISRuntimeCore" + RuntimeVersion;
string sInstallPath = Path.Combine(DeploymentHome, sRuntimeDeployment);
if (Directory.Exists(sInstallPath))
{
NativeInstallPath = Path.Combine(sInstallPath, "runtimes");
DLLversion = RuntimeVersion.Replace('.', '_');
NativeLibrary.SetDllImportResolver(typeof(ArcGISRuntimeEnvironment).Assembly, new DllImportResolver(DllImportResolver));
NativeLibrary.SetDllImportResolver(typeof(Esri.ArcGISRuntime.UI.Controls.MapView).Assembly, new DllImportResolver(DllImportResolver));
string sAssemblyPath = Path.Combine(sInstallPath, "Esri.ArcGISRuntime.dll");
AssemblyLoadContext.Default.LoadFromAssemblyPath(sAssemblyPath);
sAssemblyPath = Path.Combine(sInstallPath, "Esri.ArcGISRuntime.WPF.dll");
AssemblyLoadContext.Default.LoadFromAssemblyPath(sAssemblyPath);
}
// Initialize the ArcGIS Runtime before any components are created.
ArcGISRuntimeEnvironment.Initialize();
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString(), "ArcGIS Runtime initialization failed.");
// Exit application
this.Shutdown();
}
}
private static IntPtr DllImportResolver(string libraryName, System.Reflection.Assembly assembly, System.Runtime.InteropServices.DllImportSearchPath? searchPath)
{
string path = $"{NativeInstallPath}\\win-x{(Environment.Is64BitProcess ? "64" : "86")}\\native\\{libraryName}";
if (libraryName == "RuntimeCoreNet" + DLLversion + ".dll") // && assembly.FullName == typeof(Esri.ArcGISRuntime.ArcGISRuntimeEnvironment).Assembly.FullName)
{
if (runtimeLibPtr == IntPtr.Zero)
{
if (NativeLibrary.TryLoad(@$"{path}", out runtimeLibPtr))
return runtimeLibPtr;
}
return runtimeLibPtr;
}
else if (libraryName == "RuntimeCoreNet" + DLLversion + ".WPF.dll") // && assembly.FullName == typeof(Esri.ArcGISRuntime.UI.Controls.MapView).Assembly.FullName)
{
if (runtimeLibWpfPtr == IntPtr.Zero)
{
if (NativeLibrary.TryLoad(@$"{path}", out runtimeLibPtr))
return runtimeLibWpfPtr;
}
return runtimeLibWpfPtr;
}
return IntPtr.Zero;
}
}
}