Skip to content

[vs17.14] Replace obsolete UCOMITypeInfo with recommended System.Runtime.InteropServices.ComTypes.ITypeInfo #12012

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 19, 2025

Conversation

github-actions[bot]
Copy link
Contributor

@github-actions github-actions bot commented Jun 13, 2025

Backport of #11940 to vs17.14

Fixes https://developercommunity.visualstudio.com/t/Unable-to-build-VBNET-app-in-VS2022--17/10867825

Work item (Internal use):
AB#2495104

Summary

ClickOnce users are running into an intermittent build failure in Forms/WPF projects with COM library references where the ClickOnce manifest creation task (GenerateApplicationManifest) fails. The Isolated property on the COM reference needs to be set to true for the failure to manifest.

The System.Runtime.InteropServices.UCOMITypeInfo.ReleaseTypeAttr called in the ComImporter class throws a COMException when the task fails. The HResult in the exception is a random value instead of a standard HResult.

Below is the msbuild stack when the ClickOnce task fails:

System.Runtime.InteropServices.COMException (0xAEDCAE40): Exception from HRESULT: 0xAEDCAE40
at System.Runtime.InteropServices.UCOMITypeInfo.ReleaseTypeAttr(IntPtr pTypeAttr)
at Microsoft.Build.Tasks.Deployment.ManifestUtilities.c…ctor(String path, OutputMessageCollection outputMessages, String outputDisplayName)
at Microsoft.Build.Tasks.Deployment.ManifestUtilities.FileReference.ImportComComponent(String path, OutputMessageCollection outputMessages, String outputDisplayName)
at Microsoft.Build.Tasks.GenerateApplicationManifest.AddIsolatedComReferences(ApplicationManifest manifest)
at Microsoft.Build.Tasks.GenerateApplicationManifest.BuildApplicationManifest(ApplicationManifest manifest)
at Microsoft.Build.Tasks.GenerateManifestBase.BuildManifest()
at Microsoft.Build.Tasks.GenerateManifestBase.Execute()

The fix is to replace the UCOMITypeLib/UCOMITypeInfo classes that were obsoleted in .NET 2.0 with the recommended ITypeLib/ITypeInfo classes from System.Runtime.InteropServices.ComTypes.

The root cause appears to be that UCOMITypeInfo.ReleaseType does not have the PreserveSig attribute which may be causing the .NET Interop layer to assume a HResult return value from the method. The method returns void which is likely causing COM Interop to throw a failure based on what the return value register contains.

Customer Impact

Build failure in Forms/WPF projects with COM library reference when its Isolated property is set.

Regression?

No. There are reports of this failure on SO from several years ago. This is the first report on Developer Community feedback.

Testing

Intermittent failure is not reproducible after this change in the repro environment.
CTI test pass completed and signed off with the fix.

Risk

Low

…ypeInfo with recommended System.Runtime.InteropServices.ComTypes.ITypeInfo
@sujitnayak
Copy link
Contributor

sujitnayak commented Jun 16, 2025

Fixes #
https://developercommunity.visualstudio.com/t/Unable-to-build-VBNET-app-in-VS2022--17/10867825

Work item (Internal use):
AB# 2495104

Summary

ClickOnce users are running into an intermittent build failure in Forms/WPF projects with COM library references where the ClickOnce manifest creation task (GenerateApplicationManifest) fails. The Isolated property on the COM reference needs to be set to true for the failure to manifest.

The System.Runtime.InteropServices.UCOMITypeInfo.ReleaseTypeAttr called in the ComImporter class throws a COMException when the task fails. The HResult in the exception is a random value instead of a standard HResult.

Below is the msbuild stack when the ClickOnce task fails:

System.Runtime.InteropServices.COMException (0xAEDCAE40): Exception from HRESULT: 0xAEDCAE40
at System.Runtime.InteropServices.UCOMITypeInfo.ReleaseTypeAttr(IntPtr pTypeAttr)
at Microsoft.Build.Tasks.Deployment.ManifestUtilities.c…ctor(String path, OutputMessageCollection outputMessages, String outputDisplayName)
at Microsoft.Build.Tasks.Deployment.ManifestUtilities.FileReference.ImportComComponent(String path, OutputMessageCollection outputMessages, String outputDisplayName)
at Microsoft.Build.Tasks.GenerateApplicationManifest.AddIsolatedComReferences(ApplicationManifest manifest)
at Microsoft.Build.Tasks.GenerateApplicationManifest.BuildApplicationManifest(ApplicationManifest manifest)
at Microsoft.Build.Tasks.GenerateManifestBase.BuildManifest()
at Microsoft.Build.Tasks.GenerateManifestBase.Execute()

The fix is to replace the UCOMITypeLib/UCOMITypeInfo classes that were obsoleted in .NET 2.0 with the recommended ITypeLib/ITypeInfo classes from System.Runtime.InteropServices.ComTypes.

The root cause appears to be that UCOMITypeInfo.ReleaseType does not have the PreserveSig attribute which may be causing the .NET Interop layer to assume a HResult return value from the method. The method returns void which is likely causing COM Interop to throw a failure based on what the return value register contains.

Customer Impact

Build failure in Forms/WPF projects with COM library reference when its Isolated property is set.

Regression?

No. There are reports of this failure on SO from several years ago. This is the first report on Developer Community feedback.

Testing

Intermittent failure is not reproducible after this change in the repro environment.
CTI test pass completed and signed off with the fix.

Risk

Low

@AR-May AR-May requested a review from a team as a code owner June 17, 2025 15:27
@AR-May
Copy link
Member

AR-May commented Jun 17, 2025

Updating branch should hopefully fix those pipeline issues. Also bumped version.

@rainersigwald rainersigwald merged commit c11003a into vs17.14 Jun 19, 2025
10 checks passed
@rainersigwald rainersigwald deleted the backport/pr-11940-to-vs17.14 branch June 19, 2025 19:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants