[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

microsoft.public.dotnet.framework.interop

ReportAvOnComRelease exception

LittlePlane

4/27/2007 10:30:00 PM

Hi,
I have a c# object(ActiveX chart), and created in the unmanaged c++ code.
The chart is created when popup the dialog box, and release, disposed when
close the dialog box. But if we keep open dialog and close dialog for couple
of times, then the application will crash or disappears. It has a error
message:

Managed Debugging Assistant 'ReportAvOnComRelease' has detected a problem in
'v:\xxx.exe'.
Additional Information: An exception was caught but handled while releasing
a COM interface pointer through Marshal.Release or Marshal.ReleaseComObject
or implicitly after the corresponding RuntimeCallableWrapper was garbage
collected. This is the result of a user refcount error or other problem with
a COM object's Release. Make sure refcounts are managed properly. The COM
interface pointer's original vtable pointer was 0x78307604. While these types
of exceptions are caught by the CLR, they can still lead to corruption and
data loss so if possible the issue causing the exception should be addressed

The code is like this:
In the class of the dialog:
CComPtr<IUnknown> m_unkChart;
CWinFormsControlWnd*m_ pWin;


When create it:
---
MYChart* pChart = new MYChart();
m_unkChart = (IUnknown*)Marshal::GetIUnknownForObject(pChart ).ToPointer();
m_pWin = new CWinFormsControlWnd();
m_pWin->Create(m_unkChart, WS_VISIBLE | WS_TABSTOP, ract, this, SOME_ID);
---when release it:

System::Object *pCtrl =
Marshal::GetObjectForIUnknown((System::IntPtr)(m_unkChart));
MYChart *pChart = dynamic_cast<MYChart *>(pCtrl);
pChart->Dispose();
m_pWin->DestroyWindow();
delete m_pWin;
m_pWin = NULL;

It seems the problem is the gc in the managed code and release() in
unmanaged code conflict for the COM pointer?

Thanks in advance.