Skip to content

Replace obsolete UCOMITypeInfo with recommended System.Runtime.InteropServices.ComTypes.ITypeInfo#11940

Merged
MichalPavlik merged 1 commit intodotnet:mainfrom
sujitnayak:user/sujitn/2495104
Jun 4, 2025
Merged

Replace obsolete UCOMITypeInfo with recommended System.Runtime.InteropServices.ComTypes.ITypeInfo#11940
MichalPavlik merged 1 commit intodotnet:mainfrom
sujitnayak:user/sujitn/2495104

Conversation

@sujitnayak
Copy link
Contributor

@sujitnayak sujitnayak commented Jun 2, 2025

Fixes #
AB#2495104

Context

ClickOnce users report an intermittent build failure in Forms projects where the ClickOnce manifest creation task is running.
I was able to reproduce the issue on one of my machines intermittently where the call to System.Runtime.InteropServices.UCOMITypeInfo.ReleaseTypeAttr(...) throws a ComException with random unknown hr values.

From the documenation this type has been deprecated and replaced by System.Runtime.InteropServices.ComTypes.ITypeInfo since .NET 2.0.

Replacing the obsolete type with the recommended type fixes the issue of the random failure while calling ReleaseTypeAttr.

Changes Made

  • Replace the obsolete type UCOMITypeInfo with the recommended type ITypeInfo.
  • Ignore ComExceptions from ReleaseTypeAttr call.
  • Fix memory leak where TypeLib COM object was not being released.

Testing

Validated with private Tasks DLL that the ReleaseTypeAttr call does not fail anymore.
CTI team is also running some tests with a private tasks DLL.

Notes

…ypeInfo with recommended System.Runtime.InteropServices.ComTypes.ITypeInfo
Copilot AI review requested due to automatic review settings June 2, 2025 20:34
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR replaces the obsolete UCOMITypeInfo with the recommended System.Runtime.InteropServices.ComTypes.ITypeInfo to address intermittent build failures in Forms projects. Key changes include:

  • Replacing outdated COM interface types with ComTypes aliases.
  • Ignoring COM exceptions during the release of COM resources.
  • Fixing a memory leak by ensuring proper COM object cleanup.

@merriemcgaw merriemcgaw requested a review from JeremyKuhne June 3, 2025 00:44
@merriemcgaw
Copy link
Member

Adding @JeremyKuhne to offer thoughts, but this seems reasonable based on our discussion earlier.

@MichalPavlik MichalPavlik merged commit c743008 into dotnet:main Jun 4, 2025
10 checks passed
@rainersigwald
Copy link
Member

/backport to vs17.14

@github-actions
Copy link
Contributor

@KalleOlaviNiemitalo
Copy link

KalleOlaviNiemitalo commented Jun 13, 2025

I see ITypeInfo.ReleaseTypeAttr(IntPtr) has [PreserveSig], but UCOMITypeInfo.ReleaseTypeAttr(IntPtr) doesn't. The Win32 documentation of ITypeInfo.ReleaseTypeAttr shows it returning void, rather than HRESULT. Is the problem that the lack of [PreserveSig] causes the .NET COM interop to assume a HRESULT return value, but the method does not actually return one, so the return-value register contains garbage and .NET then throws if the failure bit happens to be set?

@sujitnayak
Copy link
Contributor Author

It could be the reason why UCOMITypeInfo.ReleaseTypeAttr throws. UCOMITypeInfo however is deprecated and this change removes its usage in favor of using ITypeInfo.

rainersigwald pushed a commit that referenced this pull request Jun 19, 2025
…ime.InteropServices.ComTypes.ITypeInfo (#12012)

Backport of #11940 to vs17.14

---------

Co-authored-by: Sujit Nayak <sujitn@microsoft.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants