зеркало из https://github.com/mono/ikvm-fork.git
- Consolidated and improved error handling in LoadFile.
- Added warning when LoadFile returns previously loaded assembly, instead of the one specified.
This commit is contained in:
Родитель
34874d8355
Коммит
54763e3a6f
|
@ -69,9 +69,15 @@ namespace IKVM.Internal
|
|||
|
||||
internal Assembly LoadFile(string path)
|
||||
{
|
||||
Assembly asm = universe.LoadFile(path);
|
||||
string ex = null;
|
||||
try
|
||||
{
|
||||
using (RawModule module = universe.OpenRawModule(path))
|
||||
{
|
||||
if (mscorlibVersion != null)
|
||||
{
|
||||
// to avoid problems (i.e. weird exceptions), we don't allow assemblies to load that reference a newer version of mscorlib
|
||||
foreach (AssemblyName asmref in asm.GetReferencedAssemblies())
|
||||
foreach (AssemblyName asmref in module.GetReferencedAssemblies())
|
||||
{
|
||||
if (asmref.Name == "mscorlib" && asmref.Version > mscorlibVersion)
|
||||
{
|
||||
|
@ -79,8 +85,31 @@ namespace IKVM.Internal
|
|||
Environment.Exit(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
Assembly asm = universe.LoadAssembly(module);
|
||||
if (asm.Location != module.Location)
|
||||
{
|
||||
Console.Error.WriteLine("Warning: assembly '{0}' is ignored as previously loaded assembly '{1}' has the same identity '{2}'", path, asm.Location, asm.FullName);
|
||||
}
|
||||
return asm;
|
||||
}
|
||||
}
|
||||
catch (IOException x)
|
||||
{
|
||||
ex = x.Message;
|
||||
}
|
||||
catch (UnauthorizedAccessException x)
|
||||
{
|
||||
ex = x.Message;
|
||||
}
|
||||
catch (IKVM.Reflection.BadImageFormatException x)
|
||||
{
|
||||
ex = x.Message;
|
||||
}
|
||||
Console.Error.WriteLine("Error: unable to load assembly '{0}'" + Environment.NewLine + " ({1})", path, ex);
|
||||
Environment.Exit(1);
|
||||
return null;
|
||||
}
|
||||
|
||||
internal Assembly LoadWithPartialName(string name)
|
||||
{
|
||||
|
@ -109,8 +138,6 @@ namespace IKVM.Internal
|
|||
{
|
||||
Assembly asm = null;
|
||||
cache.TryGetValue(reference, out asm);
|
||||
try
|
||||
{
|
||||
if (asm == null)
|
||||
{
|
||||
foreach (string found in FindAssemblyPath(reference))
|
||||
|
@ -120,10 +147,6 @@ namespace IKVM.Internal
|
|||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (FileLoadException)
|
||||
{
|
||||
}
|
||||
if (asm == null)
|
||||
{
|
||||
Console.Error.WriteLine("Error: reference not found: {0}", reference);
|
||||
|
@ -134,8 +157,6 @@ namespace IKVM.Internal
|
|||
else
|
||||
{
|
||||
foreach (string file in files)
|
||||
{
|
||||
try
|
||||
{
|
||||
Assembly asm;
|
||||
if (!cache.TryGetValue(file, out asm))
|
||||
|
@ -144,12 +165,6 @@ namespace IKVM.Internal
|
|||
}
|
||||
ArrayAppend(ref references, asm);
|
||||
}
|
||||
catch (FileLoadException)
|
||||
{
|
||||
Console.Error.WriteLine("Error: reference not found: {0}", file);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче