in csharp/NativeUtils/ResourceLoader.cs [1175:1301]
private void LoadInternal()
{
if (null == _resourcePrefix)
throw new ArgumentException("Resource path is not set, use From(resourcePathTemplate) to set");
if (null == _deploymentPathTemplate)
throw new ArgumentException("Deployment path is not set, use To(deploymentPathTemplate) to set");
if (_deploymentOptions.HasFlag(Opt.AlwaysOverwrite | Opt.ReusePartiallyDeployed))
throw new ArgumentException("AlwaysOverwrite=true is not compatible with ReusePartiallyDeployed=true");
// Fill debug info structure
Dbg("cfg.", "Config");
Dbg("res.", "Resource");
Dbg("pl.", "Platform");
Dbg("dep.", "Deployment");
Dbg("last.", "LastDeployment");
Dbg("pl.OS", VariablesMapper.OsDetected);
Dbg("pl.Arch", VariablesMapper.ArchDetected);
Dbg("res.AssemblyVersion", VariablesMapper.Version);
#if !NETSTANDARD_BELOW_2_0
Dbg("pl.RuntimeDir", RuntimeEnvironment.GetRuntimeDirectory());
Dbg("pl.ClrVersion", Environment.Version);
#endif
Dbg("cfg.resourceTemplate", _resourcePathTemplate);
Dbg("cfg.deploymentTemplate", _deploymentPathTemplate);
Dbg("cfg._deploymentPathDoSubstitution", _deploymentPathDoSubstitution);
Dbg("cfg.addRandomFallbackSubDirectory", _addRandomFallbackSubDirectory);
Dbg("cfg.retryTimeoutMs", _retryTimeoutMs);
Dbg("cfg.lockUpdatePeriodMs", _lockUpdatePeriodMs);
if (null != LockedDlls)
{
Dbg("lockedDlls.", "lockedDlls");
Dbg("lockedDlls.countBefore", LockedDlls.Count);
}
string path = _deploymentPathDoSubstitution
? VariablesMapper.Substitute(_deploymentPathTemplate) : _deploymentPathTemplate;
var paths = new List<string>();
// If user did not specify his preferred deployment root path, prepare our own
if (!Path.IsPathRooted(path))
{
#if !NETSTANDARD_BELOW_2_0
// GetFolderPath is not supported everywere, therefore it is optional
string[] rootPaths = {
// CommonApplicationData typically unavailable on Linux and on some Windows systems
Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData),
Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData)
};
foreach (var rootPath in rootPaths)
if (!string.IsNullOrEmpty(rootPath))
paths.Add(Path.Combine(rootPath, path));
#endif
// Temp dir and random subfolders in the temp dir are always enabled
var fallbackPath = Path.Combine(Path.GetTempPath(), path);
var fallbackPath2 = Path.Combine(fallbackPath, NextRandomDirString());
paths.Add(fallbackPath);
paths.Add(fallbackPath2);
FileJanitor.AddCleanupPath(fallbackPath, false, RandomDirRegEx);
}
else
{
paths.Add(path);
if (_addRandomFallbackSubDirectory)
{
paths.Add(Path.Combine(path, NextRandomDirString()));
FileJanitor.AddCleanupPath(path, false, RandomDirRegEx);
}
}
#if NETSTANDARD_BELOW_2_0
// There will be no on-exit cleanup callback for these version, try to clean immediately
FileJanitor.TryCleanup();
Dbg("dep.cleanupAt", "BeforeDeploy");
#else
FileJanitor.RegisterForCleanupOnExit();
Dbg("dep.cleanupAt", "Exit");
#endif
try
{
if (!IsAscii(_resourcePathTemplate))
Dbg("res.templateIsNonAscii", true);
if (null == _resources)
ListResources();
Dbg("res.count", _resources.Count);
Dbg("res.maxSrcLength", _maxResourceLength);
Dbg("res.dllCount", _dlCount);
Dbg("res.count", _resources.Count);
if (LogLevelLeast(DBG))
{
Log("Deployment paths:");
foreach (string p in paths)
Log(p);
}
Dbg("dep.paths", paths.ToArray());
foreach (string p in paths)
{
if (TryLoadAt(p))
return;
}
}
catch (Exception e)
{
LastDeploymentException = e;
}
// Failure!
if (null != LockedDlls)
Dbg("lockedDlls.countAfter", LockedDlls.Count);
Dbg("last.", "LastDeployment");
throw new Exception(
$"ERROR: Failed to deploy/load resources at path: \"{_lastUsedPath}\" \nConfiguration: \n{_diag}",
LastDeploymentException);
}