runtime
runtime copied to clipboard
COM event with recursion .net 6 problem
Description
We are using a system that exposes UI interface using COM objects. It is an external application so I cannot send a minimal reproduction source code of a problem. I will try to explain the whole workflow.
Background information
There is an application interface (COM) that exposes event.
Event declaration in the App interface:
event _IApplicationEvents_StatusBarEventEventHandler StatusBarEvent;
Delegate definition:
public delegate void _IApplicationEvents_StatusBarEventEventHandler([In][MarshalAs(UnmanagedType.BStr)] string Text, [In] BoStatusBarMessageType messageType);
There is also a StatusBarControl that allows us to set up the ProgressBarMessage:
application.StatusBar.SetText(“some text”);
When we set the text to the status bar Event is fired.
Reproduction Steps
UseCase: When the StatusBarEvent fires with text equal to “crush” we want to change this to "****" on the status bar
EventHandler implementation:
public override void OnStatusBarDisplayed(string text, BoStatusBarMessageType messageType)
{
if (text.Equals("crush",StringComparison.CurrentCultureIgnoreCase))
{
application.StatusBar.SetText("*****");
}
}
I will provide some screenshots of the debugging session:
- Set "crush" to the status bar.

- We get the Event notification and call the setText("****").
- System freezes. We can see that the event handler thread freezes on the set text method.

- We can see that in the separate thread invoking a method the foreach loop of _delegateWrapper.

Expected behavior
What should happen: this thread @29816 should invoke this method and Call the OnStatusBarDisplayed event again. This is working correctly when running in the .net framework.
Below is the same call stack of the .net framework debugging session. 
Calling SetText in another thread is not an option for us.
Actual behavior
System freezes. We can see that the event handler thread freezes on the set text method. 
Regression?
This is working correctly when running in the .net framework.
Known Workarounds
Calling SetText in another thread but this is not an option for us.
Configuration
.NET 6.0 Windows 11 x64
Other information
No response
I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label.
Hello I was having a similar issue. This is critical from my point of view, please consider fixing this problem with the COM object in the .net core 6 version as it is in the long-term support. Here is the reproduction repository link
https://github.com/MichalWeczorek/COM-event-with-recursion-.net-6-problem the reproduction code is using Microsoft.Office.Interop.Excel COM library
if you debug the .net6 version it freezes if you debug in .net framework 4.72 all works correctly.
Thanks
Hi @jeffschwMSFT, Is there any chance that somebody will check if there is any chance to fix this issue in .NET 6, which is LTS, and we would love to use it now, instead of waiting for .NET 8?
We are completely stuck with our migration from .NET Framework to .NET 6 until this issue is resolved, or we have some workable workaround. Unfortunately, so far, we haven't found any. The code is working fine on the .NET Framework. Still, it hangs on .NET 6. @MichalWeczorek, in his previous comment, provided reproduction on the Excel COM library, so this problem is not specific to our code base or any particular external API.
I highly appreciate any support which you can provide. Thank you very much!
Thank you for providing details on the impact. On process is to first fix it in our primary branch and then consider backporting. Adding some folks that might be able to offer a suggested workaround in the meantime.
cc @jkoritzinsky @elinor-fung @AaronRobinsonMSFT
I don't know of the correct fix here as I've just not had time to take a look. To be honest I was considering this very low priority because of COM Events. I can make some time when I get back if this is a priority. I don't know of a workaround without debugging.
arr
Sent from Outlookhttp://aka.ms/weboutlook
From: Jeff Schwartz @.> Sent: Friday, September 9, 2022 06:42 To: dotnet/runtime @.> Cc: Aaron Robinson @.>; Mention @.> Subject: Re: [dotnet/runtime] COM event with recursion .net 6 problem (Issue #73754)
Thank you for providing details on the impact. On process is to first fix it in our primary branch and then consider backporting. Adding some folks that might be able to offer a suggested workaround in the meantime.
cc @jkoritzinskyhttps://nam06.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fjkoritzinsky&data=05%7C01%7Carobins%40microsoft.com%7C7db719802ae84c53707608da92691c69%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C637983277393629700%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=budYudl7S3n78qoTs4m2PHCwmw%2BbZO0zPcO3KdvjtiM%3D&reserved=0 @elinor-funghttps://nam06.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Felinor-fung&data=05%7C01%7Carobins%40microsoft.com%7C7db719802ae84c53707608da92691c69%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C637983277393629700%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=66TKI9Gf5V2pTO7cLwbYZi8O76cE4kRwTuiLG1gOcxw%3D&reserved=0 @AaronRobinsonMSFThttps://nam06.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2FAaronRobinsonMSFT&data=05%7C01%7Carobins%40microsoft.com%7C7db719802ae84c53707608da92691c69%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C637983277393785939%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=Guwq6xwt%2BN9MYHUxcns2OkTVb%2BUXaDVFM9FFwTg4g0k%3D&reserved=0
— Reply to this email directly, view it on GitHubhttps://nam06.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fdotnet%2Fruntime%2Fissues%2F73754%23issuecomment-1241991160&data=05%7C01%7Carobins%40microsoft.com%7C7db719802ae84c53707608da92691c69%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C637983277393785939%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=KkaduD%2F5MK0z2ffRcVWPTwd7mIglKsu2pahqDkgNQJQ%3D&reserved=0, or unsubscribehttps://nam06.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fnotifications%2Funsubscribe-auth%2FAHJXMLPVJPH7IT7K5A2VO33V5M5DRANCNFSM56HIRRIQ&data=05%7C01%7Carobins%40microsoft.com%7C7db719802ae84c53707608da92691c69%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C637983277393785939%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=xOrewhhhWTpcuA0DhxJxN9OcpPQEuE085eNrJdO3dSs%3D&reserved=0. You are receiving this because you were mentioned.Message ID: @.***>
Thank you for your prompt reaction!
@AaronRobinsonMSFT, from our point of view, it's critical as the application hangs, and there is no known workaround.
In the repo https://github.com/MichalWeczorek/COM-event-with-recursion-.net-6-problem, there's ready code for debugging. We are also happy to provide any required feedback to resolve this issue.
Keeping our fingers crossed for your findings and fixing this issue :). Thank you.
@MichalWeczorek Thank you for the simple reproduction. I was able to immediately root out the issue. This has been present since we introduced COM events back in .NET Core 3.1. As soon as I get sign-off for .NET 8, I will work to get it into .NET 7 and possibly .NET 6.
I'm pleased that this issue is moving forward. I am waiting to hear more good news soon. Thank you @AaronRobinsonMSFT
@MichalWeczorek and @lukaszch A fix has been checked into .NET 8. I have filed servicing requests for .NET 6 and .NET 7. You can following them at: https://github.com/dotnet/runtime/pull/76035 and https://github.com/dotnet/runtime/pull/76034.
Thank you @AaronRobinsonMSFT for your quick reaction to fix this issue. It's simply amazing :).