diff --git a/reflect/AssemblyName.cs b/reflect/AssemblyName.cs index 37bb54fe..1fcfc0a2 100644 --- a/reflect/AssemblyName.cs +++ b/reflect/AssemblyName.cs @@ -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); } } } diff --git a/reflect/Reader/ModuleReader.cs b/reflect/Reader/ModuleReader.cs index a3819e96..3f99c9fd 100644 --- a/reflect/Reader/ModuleReader.cs +++ b/reflect/Reader/ModuleReader.cs @@ -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()