Skip to content

Commit

Permalink
Demand-load tlbs instead of always loading them
Browse files Browse the repository at this point in the history
  • Loading branch information
Arakys7 committed Nov 22, 2024
1 parent 7fa354e commit 9d91a52
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 16 deletions.
30 changes: 15 additions & 15 deletions src/dscom/TypeInfoResolver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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));
}

}
1 change: 0 additions & 1 deletion src/dscom/writer/LibraryWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ public override void Create()
}

Context.TypeInfoResolver.AddTypeLib((ITypeLib)typeLib);
Context.TypeInfoResolver.AddAdditionalTypeLibs();

if (!string.IsNullOrEmpty(Context.Options.Out))
{
Expand Down

0 comments on commit 9d91a52

Please sign in to comment.