You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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 from System.Windows.Forms.AxHost. In all versions of .NET prior to 8.0, the destructor of the OCX would be invoked upon calling the Dispose() method on the AxHost 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 to Marshal.FinalReleaseComObject(_instance) within the method ReleaseAxControl() of class AxHost, which effectively triggered the OCX's destructor. But with .NET 8, the code has been changed to call Marshal.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:
Launch Visual Studio 2022.
Create a new project using the MFC ActiveX Control template.
Name the project MFCActiveXControl.
Modify the Control's Constructor and Destructor:
Open the MFCActiveXControlCtrl.cpp file.
Update the constructor and destructor to include console output for logging purposes:
#include<iostream>CMFCActiveXControlCtrl::CMFCActiveXControlCtrl()
{
std::cout << "constructor called";
InitializeIIDs(&IID_DMFCActiveXControl, &IID_DMFCActiveXControlEvents);
// TODO: Initialize your control's instance data here.
}
CMFCActiveXControlCtrl::~CMFCActiveXControlCtrl()
{
std::cout << "destructor called";
// TODO: Cleanup your control's instance data here.
}
Compile the Project:
Set the build configuration to 'Release'.
Compile the project to generate the MFCActiveXControl.ocx file.
Register the Compiled OCX:
Open PowerShell as an administrator.
Execute the following command to register the OCX file:
Reference both MFCActiveXControlLib.dll and AxMFCActiveXControlLib.dll in your ConsoleClient project.
Update the Main Program File:
Replace the contents of Program.cs with the following code:
using System;using AxMFCActiveXControlLib;namespaceConsoleClient{internalclassProgram{[STAThread]staticvoidMain(string[]args){varocx=new AxMFCActiveXControl();
ocx.CreateControl();
ocx.Dispose();}}}
Compile and Run the C# Application:
Build the ConsoleClient application.
Run the application and observe the console output: "Constructor called." followed by "Destructor called."
Update to .NET 8:
Change the target framework to .NET 8 by updating the project file:
<TargetFramework>net8.0-windows</TargetFramework>
Rebuild the ConsoleClient application.
Re-run the Application:
Run the updated ConsoleClient application and observe that the console output displays only "Constructor called." This indicates that the destructor is not being invoked as expected.
The text was updated successfully, but these errors were encountered:
.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: