From 9d91a52236491c6bfa351c210a20399cd2b2665b Mon Sep 17 00:00:00 2001 From: Arakys7 Date: Fri, 22 Nov 2024 14:15:15 -0800 Subject: [PATCH] Demand-load tlbs instead of always loading them --- src/dscom/TypeInfoResolver.cs | 30 +++++++++++++++--------------- src/dscom/writer/LibraryWriter.cs | 1 - 2 files changed, 15 insertions(+), 16 deletions(-) diff --git a/src/dscom/TypeInfoResolver.cs b/src/dscom/TypeInfoResolver.cs index d7b8e703..2e256792 100644 --- a/src/dscom/TypeInfoResolver.cs +++ b/src/dscom/TypeInfoResolver.cs @@ -106,31 +106,37 @@ public TypeInfoResolver(WriterContext writerContext) } else { - var assembly = type.Assembly; - var identifier = assembly.GetLibIdentifier(WriterContext.Options.OverrideTlbId); - retval = ResolveTypeInfo(type.GUID); if (retval == null) { + var assembly = type.Assembly; + var identifier = assembly.GetLibIdentifier(WriterContext.Options.OverrideTlbId); + var typeLib = GetTypeLibFromIdentifier(identifier); if (typeLib == null) { + foreach (var additionalLib in _additionalLibs) + { + var name = assembly.GetName().Name ?? string.Empty; + if (additionalLib.Contains(name)) + { + AddTypeLib(additionalLib); + retval = ResolveTypeInfo(type.GUID); + break; + } + } + var notifySink = WriterContext.NotifySink; if (notifySink != null) { if (notifySink.ResolveRef(assembly) is ITypeLib refTypeLib) { AddTypeLib(refTypeLib); - typeLib = refTypeLib; + retval = ResolveTypeInfo(type.GUID); } } } - - if (typeLib != null) - { - retval = ResolveTypeInfo(type.GUID); - } } } _resolvedTypeInfos[type] = retval; @@ -272,10 +278,4 @@ public bool AddTypeLib(string typeLibPath) OleAut32.LoadTypeLibEx(typeLibPath, REGKIND.NONE, out var typeLib).ThrowIfFailed($"Failed to load type library {typeLibPath}."); return AddTypeLib(typeLib); } - - public void AddAdditionalTypeLibs() - { - _additionalLibs.ForEach(typeLib => AddTypeLib(typeLib)); - } - } diff --git a/src/dscom/writer/LibraryWriter.cs b/src/dscom/writer/LibraryWriter.cs index a6b13ec6..ef08eb32 100644 --- a/src/dscom/writer/LibraryWriter.cs +++ b/src/dscom/writer/LibraryWriter.cs @@ -61,7 +61,6 @@ public override void Create() } Context.TypeInfoResolver.AddTypeLib((ITypeLib)typeLib); - Context.TypeInfoResolver.AddAdditionalTypeLibs(); if (!string.IsNullOrEmpty(Context.Options.Out)) {