diff --git a/eng/Versions.props b/eng/Versions.props index 57fafd35799..711a6542f24 100644 --- a/eng/Versions.props +++ b/eng/Versions.props @@ -2,7 +2,7 @@ - 17.14.13release + 17.14.14release 17.13.9 15.1.0.0 servicing diff --git a/src/Tasks/ManifestUtil/ComImporter.cs b/src/Tasks/ManifestUtil/ComImporter.cs index b4678e65365..65a15ebb52f 100644 --- a/src/Tasks/ManifestUtil/ComImporter.cs +++ b/src/Tasks/ManifestUtil/ComImporter.cs @@ -7,9 +7,7 @@ using System.Globalization; using System.Resources; using System.Runtime.InteropServices; -#if RUNTIME_TYPE_NETCORE -using System.Runtime.InteropServices.ComTypes; -#endif +using ComTypes = System.Runtime.InteropServices.ComTypes; using System.Runtime.Versioning; #nullable disable @@ -55,64 +53,86 @@ public ComImporter(string path, OutputMessageCollection outputMessages, string o catch (COMException) { } #pragma warning disable 618 -#if RUNTIME_TYPE_NETCORE - ITypeLib tlib = (ITypeLib)obj; -#else - UCOMITypeLib tlib = (UCOMITypeLib)obj; -#endif + ComTypes.ITypeLib tlib = (ComTypes.ITypeLib)obj; if (tlib != null) { IntPtr typeLibAttrPtr = IntPtr.Zero; - tlib.GetLibAttr(out typeLibAttrPtr); - var typeLibAttr = (TYPELIBATTR)Marshal.PtrToStructure(typeLibAttrPtr, typeof(TYPELIBATTR)); - tlib.ReleaseTLibAttr(typeLibAttrPtr); - Guid tlbid = typeLibAttr.guid; - - tlib.GetDocumentation(-1, out _, out string docString, out _, out string helpFile); - string helpdir = Util.FilterNonprintableChars(helpFile); // Path.GetDirectoryName(helpFile); - - TypeLib = new TypeLib(tlbid, new Version(typeLibAttr.wMajorVerNum, typeLibAttr.wMinorVerNum), helpdir, typeLibAttr.lcid, Convert.ToInt32(typeLibAttr.wLibFlags, CultureInfo.InvariantCulture)); - - var comClassList = new List(); - int count = tlib.GetTypeInfoCount(); - for (int i = 0; i < count; ++i) + try { - tlib.GetTypeInfoType(i, out TYPEKIND tkind); - if (tkind == TYPEKIND.TKIND_COCLASS) - { -#if RUNTIME_TYPE_NETCORE - tlib.GetTypeInfo(i, out ITypeInfo tinfo); -#else - tlib.GetTypeInfo(i, out UCOMITypeInfo tinfo); -#endif + tlib.GetLibAttr(out typeLibAttrPtr); + var typeLibAttr = (ComTypes.TYPELIBATTR)Marshal.PtrToStructure(typeLibAttrPtr, typeof(ComTypes.TYPELIBATTR)); + Guid tlbid = typeLibAttr.guid; - IntPtr tinfoAttrPtr = IntPtr.Zero; - tinfo.GetTypeAttr(out tinfoAttrPtr); - TYPEATTR tinfoAttr = (TYPEATTR)Marshal.PtrToStructure(tinfoAttrPtr, typeof(TYPEATTR)); - tinfo.ReleaseTypeAttr(tinfoAttrPtr); - Guid clsid = tinfoAttr.guid; + tlib.GetDocumentation(-1, out _, out string docString, out _, out string helpFile); + string helpdir = Util.FilterNonprintableChars(helpFile); // Path.GetDirectoryName(helpFile); - tlib.GetDocumentation(i, out _, out docString, out _, out helpFile); - string description = Util.FilterNonprintableChars(docString); + TypeLib = new TypeLib(tlbid, new Version(typeLibAttr.wMajorVerNum, typeLibAttr.wMinorVerNum), helpdir, typeLibAttr.lcid, Convert.ToInt32(typeLibAttr.wLibFlags, CultureInfo.InvariantCulture)); - ClassInfo info = GetRegisteredClassInfo(clsid); - if (info == null) + var comClassList = new List(); + int count = tlib.GetTypeInfoCount(); + for (int i = 0; i < count; ++i) + { + tlib.GetTypeInfoType(i, out ComTypes.TYPEKIND tkind); + if (tkind == ComTypes.TYPEKIND.TKIND_COCLASS) { - continue; + IntPtr tinfoAttrPtr = IntPtr.Zero; + tlib.GetTypeInfo(i, out ComTypes.ITypeInfo tinfo); + try + { + tinfo.GetTypeAttr(out tinfoAttrPtr); + ComTypes.TYPEATTR tinfoAttr = (ComTypes.TYPEATTR)Marshal.PtrToStructure(tinfoAttrPtr, typeof(ComTypes.TYPEATTR)); + Guid clsid = tinfoAttr.guid; + + tlib.GetDocumentation(i, out _, out docString, out _, out helpFile); + string description = Util.FilterNonprintableChars(docString); + + ClassInfo info = GetRegisteredClassInfo(clsid); + if (info == null) + { + continue; + } + comClassList.Add(new ComClass(tlbid, clsid, info.Progid, info.ThreadingModel, description)); + } + finally + { + try + { + if (tinfoAttrPtr != IntPtr.Zero) + { + tinfo.ReleaseTypeAttr(tinfoAttrPtr); + } + Marshal.ReleaseComObject(tinfo); + tinfo = null; + } + // Ignore COM exceptions when releasing type attributes. + catch (COMException) {} + } } - - comClassList.Add(new ComClass(tlbid, clsid, info.Progid, info.ThreadingModel, description)); + } + if (comClassList.Count > 0) + { + ComClasses = comClassList.ToArray(); + Success = true; + } + else + { + outputMessages.AddErrorMessage("GenerateManifest.ComImport", outputDisplayName, _resources.GetString("ComImporter.NoRegisteredClasses")); + Success = false; } } - if (comClassList.Count > 0) - { - ComClasses = comClassList.ToArray(); - Success = true; - } - else + finally { - outputMessages.AddErrorMessage("GenerateManifest.ComImport", outputDisplayName, _resources.GetString("ComImporter.NoRegisteredClasses")); - Success = false; + try + { + if (typeLibAttrPtr != IntPtr.Zero) + { + tlib.ReleaseTLibAttr(typeLibAttrPtr); + } + Marshal.ReleaseComObject(tlib); + tlib = null; + } + // Ignore COM exceptions when releasing type attributes. + catch (COMException) {} } } else