protected virtual AssemblyIdentity GetCoreAssemblySymbolicIdentity() {
Contract.Ensures(Contract.Result<AssemblyIdentity>() != null);
AssemblyIdentity/*?*/ result = null;
IUnit referringUnit = Dummy.Unit;
if (this.unitCache.Count > 0) {
var dummyVersion = new Version(255, 255, 255, 255);
lock (GlobalLock.LockingObject) {
foreach (IUnit unit in this.unitCache.Values) {
Contract.Assume(unit != null);
AssemblyIdentity coreId = unit.CoreAssemblySymbolicIdentity;
if (coreId.Name.Value.Length == 0) continue;
this.coreIdentities.Add(coreId);
if (result == null || result.Version == dummyVersion ||
(result.Version < coreId.Version && coreId.Version != dummyVersion) ||
result.Version == coreId.Version && unit.UnitIdentity.Equals(coreId)) {
result = coreId;
referringUnit = unit;
}
}
}
}
if (result == null) {
//If we get here, none of the assemblies in the unit cache has an opinion on the identity of the core assembly.
//Usually this will be because this method was called before any assemblies have been loaded.
//In this case, we have little option but to choose the identity of the core assembly of the platform we are running on.
var coreAssemblyName = typeof(object).Assembly.GetName();
var version = coreAssemblyName.Version;
Contract.Assume(version != null);
var publicKeyToken = coreAssemblyName.GetPublicKeyToken();
Contract.Assume(publicKeyToken != null);
result = new AssemblyIdentity(this.NameTable.GetNameFor(coreAssemblyName.Name), "", version, publicKeyToken, "");
}
if (result.Location.Length == 0) {
//We either found a plausible identity by polling the assemblies in the unit cache, or we used the identity of our own core assembly.
//However, we defer to ProbeAssemblyReference to find an actual location for the assembly.
//(Note that if result.Location.Length > 0, then the core assembly has already been loaded and we thus know the location and don't have to probe.)
this.coreAssemblySymbolicIdentity = result; //in case ProbeAssemblyReference wants to know the core identity
result = this.ProbeAssemblyReference(referringUnit, result);
}
return this.coreAssemblySymbolicIdentity = result;
}