Make ComHost.Create throw InvalidTypeLibraryException if type library is empty file...
authoranatawa12 <anatawa12@icloud.com>
Wed, 9 Aug 2023 13:53:36 +0000 (22:53 +0900)
committerGitHub <noreply@github.com>
Wed, 9 Aug 2023 13:53:36 +0000 (06:53 -0700)
src/installer/managed/Microsoft.NET.HostModel/ComHost/ComHost.cs

index 03a7276..4dfb778 100644 (file)
@@ -11,7 +11,6 @@ namespace Microsoft.NET.HostModel.ComHost
 {
     public class ComHost
     {
-        private const int E_INVALIDARG = unchecked((int)0x80070057);
         // These need to match RESOURCEID_CLSIDMAP and RESOURCETYPE_CLSIDMAP defined in comhost.h.
         private const int ClsidmapResourceId = 64;
         private const int ClsidmapResourceType = 1024;
@@ -61,16 +60,15 @@ namespace Microsoft.NET.HostModel.ComHost
                         try
                         {
                             byte[] tlbFileBytes = File.ReadAllBytes(typeLibrary.Value);
+                            if (tlbFileBytes.Length == 0)
+                                throw new InvalidTypeLibraryException(typeLibrary.Value);
+
                             updater.AddResource(tlbFileBytes, "typelib", (IntPtr)typeLibrary.Key);
                         }
                         catch (FileNotFoundException ex)
                         {
                             throw new TypeLibraryDoesNotExistException(typeLibrary.Value, ex);
                         }
-                        catch (HResultException hr) when (hr.Win32HResult == E_INVALIDARG)
-                        {
-                            throw new InvalidTypeLibraryException(typeLibrary.Value, hr);
-                        }
                     }
                 }
                 updater.Update();