Fixed AssemblyName.GetAssemblyName() to throw the proper exceptions (and by consequence Universe.LoadFile() now also throws the proper exceptions, module a race condition).

This commit is contained in:
jfrijters 2010-05-06 06:45:30 +00:00
Родитель b790897da7
Коммит f72c9f6cf8
2 изменённых файлов: 23 добавлений и 4 удалений

Просмотреть файл

@ -149,12 +149,27 @@ namespace IKVM.Reflection
} }
public static AssemblyName GetAssemblyName(string path) public static AssemblyName GetAssemblyName(string path)
{
try
{ {
using (FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read)) using (FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read))
{ {
ModuleReader module = new ModuleReader(null, null, fs, path); ModuleReader module = new ModuleReader(null, null, fs, path);
if (module.Assembly == null)
{
throw new BadImageFormatException("Module does not contain a manifest");
}
return module.Assembly.GetName(); return module.Assembly.GetName();
} }
} }
catch (IOException x)
{
throw new FileNotFoundException(x.Message, x);
}
catch (UnauthorizedAccessException x)
{
throw new FileNotFoundException(x.Message, x);
}
}
} }
} }

Просмотреть файл

@ -103,7 +103,11 @@ namespace IKVM.Reflection.Reader
this.stream = stream; this.stream = stream;
this.location = location; this.location = location;
Read(); Read();
this.assembly = assembly ?? new AssemblyReader(location, this); if (assembly == null && AssemblyTable.records.Length != 0)
{
assembly = new AssemblyReader(location, this);
}
this.assembly = assembly;
} }
private void Read() private void Read()