-
Notifications
You must be signed in to change notification settings - Fork 984
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
.Net 8 upgrade results in missing destructor call of ActiveXControl from interop assembly generated with AxImp.exe #12056
Comments
In general it is terrible form to keep calling release in a loop. @lonitra can you check what the ref counts are in ReleaseAxControl are in 8 and 9? |
Facing the same issue, is there any progress? |
This fix will be available in 8.0.11 release, which I believe is November 5 |
This came unexpectedly fast after beeing labeled with .Net 10. Thank you. |
Verified this issue on .NET SDK 10.0.100-alpha.1.2459.21 private dlls build from latest WinForms main repo, the issue has been fixed: Running the ConsoleClient application will display "Constructor called." and "Destructor called." issue.verification.mp4 |
Verified this issue on .NET SDK 8.0.10 private dlls build from latest WinForms Release/8.0 repo, the issue has been fixed: Running the ConsoleClient application will display "Constructor called." and "Destructor called." |
Verified with .NET SDK 8.0.11 test pass build, it was fixed as above testing result. |
Works like a charm also in the realworld application. Good job. |
.NET version
net8.0-windows
Did it work in .NET Framework?
Yes
Did it work in any of the earlier releases of .NET Core or .NET 5 ?
All versions before .Net 8
Issue description
I have an ActiveX control (OCX) that is integrated into a .NET application. To create the .NET interop assemblies, I use
AxImp.exe
, which generates a class that inherits fromSystem.Windows.Forms.AxHost
. In all versions of .NET prior to 8.0, the destructor of the OCX would be invoked upon calling theDispose()
method on theAxHost
instance. However, with the introduction of .NET 8, the destructor is no longer called.Specifically, in .NET 7, invoking
Dispose()
would lead to a call toMarshal.FinalReleaseComObject(_instance)
within the methodReleaseAxControl()
of classAxHost
, which effectively triggered the OCX's destructor. But with .NET 8, the code has been changed to callMarshal.ReleaseComObject(_instance)
instead, and as a result, the destructor of the OCX is not being executed anymore. This change in behavior is causing issues with resource management in the application.Steps to reproduce
Create a New MFC ActiveX Control Project:
MFCActiveXControl
.Modify the Control's Constructor and Destructor:
MFCActiveXControlCtrl.cpp
file.Compile the Project:
MFCActiveXControl.ocx
file.Register the Compiled OCX:
Generate .NET Interop Assemblies:
Add a .Net 7 C# Console Application:
Add References to the Generated DLLs:
MFCActiveXControlLib.dll
andAxMFCActiveXControlLib.dll
in your ConsoleClient project.Update the Main Program File:
Compile and Run the C# Application:
Update to .NET 8:
Re-run the Application:
The text was updated successfully, but these errors were encountered: