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 удалений

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

@ -150,10 +150,25 @@ namespace IKVM.Reflection
public static AssemblyName GetAssemblyName(string path)
{
using (FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read))
try
{
ModuleReader module = new ModuleReader(null, null, fs, path);
return module.Assembly.GetName();
using (FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read))
{
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();
}
}
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.location = location;
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()