private Assembly Extract(string id) {
if (_references == null) return null;
if (OptionDirectLoading && _references.GetObject(id + "//direct") as bool? == true) {
var sw = Stopwatch.StartNew();
var data = GetData(id);
var unpacking = sw.ElapsedMilliseconds;
sw.Restart();
var assembly = Assembly.Load(data);
if (_logFilename != null) {
Log("Direct: " + id + ", unpacking=" + unpacking + " ms, loading=" + sw.ElapsedMilliseconds + " ms");
}
return assembly;
}
Assembly result = null;
string filename;
try {
filename = ExtractToFile(id);
} catch (Exception e) {
Log("Error: " + e);
return null;
}
int i;
for (i = 1; i < 20; i++) {
try {
result = Assembly.LoadFrom(filename);
break;
} catch (FileLoadException) {
Log("FileLoadException! Next attempt in 500 ms");
Thread.Sleep(500);
}
}
if (result == null) throw new Exception("Can’t access unpacked library");
if (i > 1) {
Log($"{i + 1} attempt is successfull");
}
return result;
}