-
Interface leaks in C#?
I am getting a number of interface leaks from a simple C# application that
uses a standard COM component. If I point Visual Studio Debug at the
compiled C# application and debug it the console shows a number of interface
leaks. I have included the C# source and the errors below. Any ideas would
be greatly appreciated, or maybe I just need to wait for at least a beta
version. I don't get these leaks when using the COM component from within
VBScript or JScript.
Thank you.
Kevin Burton
kevin.burton@inewsroom.com
using System;
using System.Collections;
using AvstarNRCSLib;
class NRCS
{
static void Main()
{
Console.WriteLine("Hello, World");
ISignon signon = (ISignon)new __AnSignon();
signon.Signon("avstar", "avstar", "172.27.18.77", "", "");
if (signon.IsSignon() != 0)
{
Console.WriteLine("Signed on!");
IDirectory dir = (IDirectory)signon.get_Directory(".");
foreach(Object item in (IEnumerable)dir) {
if(item is IDirectory) {
IDirectory ld = (IDirectory)item;
Console.WriteLine(ld.Name + " Directory");
}
else if(item is IQueue) {
IQueue lq = (IQueue)item;
IStory lss;
int limit = 10000;
Console.WriteLine(lq.Name + " Queue");
if(lq.Name == "DEAD") {
limit = 100;
}
}
else if(item is IStory) {
IStory ls = (IStory)item;
Console.WriteLine(ls.Name + " Story");
}
}
signon.Signoff();
}
else
{
Console.WriteLine("Error signing on!");
}
}
}
INTERFACE LEAK: RefCount = 1, MaxRefCount = 4, {Allocation = 7}
CAnDirectory - IUnknown
INTERFACE LEAK: RefCount = 1, MaxRefCount = 2, {Allocation = 69}
CAnDirectory - IDispatch
NonAddRef Thunk LEAK: {Allocation = 70}
INTERFACE LEAK: RefCount = 2, MaxRefCount = 2, {Allocation = 71} CAnQueue -
IDispatch
NonAddRef Thunk LEAK: {Allocation = 72}
INTERFACE LEAK: RefCount = 2, MaxRefCount = 2, {Allocation = 73}
CAnDirectory - IDispatch
NonAddRef Thunk LEAK: {Allocation = 74}
INTERFACE LEAK: RefCount = 2, MaxRefCount = 2, {Allocation = 75}
CAnDirectory - IDispatch
NonAddRef Thunk LEAK: {Allocation = 76}
INTERFACE LEAK: RefCount = 2, MaxRefCount = 2, {Allocation = 77}
CAnDirectory - IDispatch
NonAddRef Thunk LEAK: {Allocation = 78}
INTERFACE LEAK: RefCount = 2, MaxRefCount = 2, {Allocation = 79} CAnQueue -
IDispatch
NonAddRef Thunk LEAK: {Allocation = 80}
INTERFACE LEAK: RefCount = 2, MaxRefCount = 2, {Allocation = 81}
CAnDirectory - IDispatch
NonAddRef Thunk LEAK: {Allocation = 82}
INTERFACE LEAK: RefCount = 2, MaxRefCount = 2, {Allocation = 83} CAnQueue -
IDispatch
NonAddRef Thunk LEAK: {Allocation = 84}
INTERFACE LEAK: RefCount = 2, MaxRefCount = 2, {Allocation = 85} CAnQueue -
IDispatch
NonAddRef Thunk LEAK: {Allocation = 86}
INTERFACE LEAK: RefCount = 2, MaxRefCount = 2, {Allocation = 87} CAnQueue -
IDispatch
NonAddRef Thunk LEAK: {Allocation = 88}
INTERFACE LEAK: RefCount = 2, MaxRefCount = 2, {Allocation = 89}
CAnDirectory - IDispatch
NonAddRef Thunk LEAK: {Allocation = 90}
INTERFACE LEAK: RefCount = 2, MaxRefCount = 2, {Allocation = 91}
CAnDirectory - IDispatch
NonAddRef Thunk LEAK: {Allocation = 92}
INTERFACE LEAK: RefCount = 2, MaxRefCount = 2, {Allocation = 93}
CAnDirectory - IDispatch
NonAddRef Thunk LEAK: {Allocation = 94}
INTERFACE LEAK: RefCount = 2, MaxRefCount = 2, {Allocation = 95}
CAnDirectory - IDispatch
NonAddRef Thunk LEAK: {Allocation = 96}
INTERFACE LEAK: RefCount = 2, MaxRefCount = 2, {Allocation = 97}
CAnDirectory - IDispatch
NonAddRef Thunk LEAK: {Allocation = 98}
INTERFACE LEAK: RefCount = 2, MaxRefCount = 2, {Allocation = 99}
CAnDirectory - IDispatch
NonAddRef Thunk LEAK: {Allocation = 100}
INTERFACE LEAK: RefCount = 2, MaxRefCount = 2, {Allocation = 101}
CAnDirectory - IDispatch
NonAddRef Thunk LEAK: {Allocation = 102}
INTERFACE LEAK: RefCount = 2, MaxRefCount = 2, {Allocation = 103}
CAnDirectory - IDispatch
NonAddRef Thunk LEAK: {Allocation = 104}
INTERFACE LEAK: RefCount = 2, MaxRefCount = 2, {Allocation = 105}
CAnDirectory - IDispatch
NonAddRef Thunk LEAK: {Allocation = 106}
INTERFACE LEAK: RefCount = 2, MaxRefCount = 2, {Allocation = 107}
CAnDirectory - IDispatch
NonAddRef Thunk LEAK: {Allocation = 108}
INTERFACE LEAK: RefCount = 2, MaxRefCount = 2, {Allocation = 109}
CAnDirectory - IDispatch
NonAddRef Thunk LEAK: {Allocation = 110}
INTERFACE LEAK: RefCount = 2, MaxRefCount = 2, {Allocation = 111}
CAnDirectory - IDispatch
NonAddRef Thunk LEAK: {Allocation = 112}
INTERFACE LEAK: RefCount = 2, MaxRefCount = 2, {Allocation = 113}
CAnDirectory - IDispatch
NonAddRef Thunk LEAK: {Allocation = 114}
INTERFACE LEAK: RefCount = 2, MaxRefCount = 2, {Allocation = 115}
CAnDirectory - IDispatch
NonAddRef Thunk LEAK: {Allocation = 116}
INTERFACE LEAK: RefCount = 2, MaxRefCount = 2, {Allocation = 117} CAnQueue -
IDispatch
NonAddRef Thunk LEAK: {Allocation = 118}
INTERFACE LEAK: RefCount = 2, MaxRefCount = 2, {Allocation = 119} CAnQueue -
IDispatch
NonAddRef Thunk LEAK: {Allocation = 120}
INTERFACE LEAK: RefCount = 2, MaxRefCount = 2, {Allocation = 121} CAnQueue -
IDispatch
NonAddRef Thunk LEAK: {Allocation = 122}
INTERFACE LEAK: RefCount = 2, MaxRefCount = 2, {Allocation = 123}
CAnDirectory - IDispatch
INTERFACE LEAK: RefCount = 1, MaxRefCount = 2, {Allocation = 124}
_CComEnum - IUnknown
INTERFACE LEAK: RefCount = 2, MaxRefCount = 2, {Allocation = 125}
_CComEnum - IEnumVARIANT
-
Re: Interface leaks in C#?
Kevin,
For now I suggest you add a System.GC.RequestFinalizeOnShutdown() call at
the top of your main method. Otherwise the garbage collector will not
attempt to finalize objects (and thus release the com objects) before
shutting down the application.
"Kevin Burton" <kevin.burton@avstarnews.com> wrote in message
news:39d8d95a$1@news.devx.com...
> I am getting a number of interface leaks from a simple C# application that
> uses a standard COM component. If I point Visual Studio Debug at the
> compiled C# application and debug it the console shows a number of
interface
> leaks. I have included the C# source and the errors below. Any ideas would
> be greatly appreciated, or maybe I just need to wait for at least a beta
> version. I don't get these leaks when using the COM component from within
> VBScript or JScript.
>
> Thank you.
>
> Kevin Burton
> kevin.burton@inewsroom.com
-
Re: Interface leaks in C#?
Thank you for your suggestions. I tired adding
GC.RequestFinalizeOnShutdown() at the top of 'Main' but now I am getting an
assertion "ATL: ERROR - Object deleted before windows was destroyed." This
is happening in the CAnSignon class that implements the ISignon interface
and also inherits from ATL::CWindowImpl to help with the connection points.
How do I destroy window before the object? A stack trace is included below,
maybe that helps.
Kevin
ATL::CWindowImplRoot<ATL::CWindow>::~CWindowImplRoot<ATL::CWindow>() line
1903 + 41 bytes
ATL::CWindowImplBaseT<ATL::CWindow,ATL::CWinTraits<1442840576,0>
>::~CWindowImplBaseT<ATL::CWindow,ATL::CWinTraits<1442840576,0> >() + 20
bytes
ATL::CWindowImpl<CAnSignon,ATL::CWindow,ATL::CWinTraits<1442840576,0>
>::~CWindowImpl<CAnSignon,ATL::CWindow,ATL::CWinTraits<1442840576,0> >() +
20 bytes
CAnSignon::~CAnSignon() line 156 + 243 bytes
ATL::CComObject<CAnSignon>::~CComObject<CAnSignon>() line 2411 + 15 bytes
ATL::CComObject<CAnSignon>::`scalar deleting destructor'(unsigned int
0x00000001) + 20 bytes
ATL::CComObject<CAnSignon>::Release(ATL::CComObject<CAnSignon> * const
0x048e0a78) line 2419 + 31 bytes
ATL::_QIThunk::Release(ATL::_QIThunk * const 0x048e0d50) line 2734
BCCORE! 0c07be4c()
MSCORWKS! 6d0a4ba0()
MSCORWKS! 6d0a53b7()
MSCORWKS! 6d054d7e
"Jeff Peil" <jpeil@bigfoot.com> wrote in message
news:39d8dac8$1@news.devx.com...
> Kevin,
>
> For now I suggest you add a System.GC.RequestFinalizeOnShutdown() call at
> the top of your main method. Otherwise the garbage collector will not
> attempt to finalize objects (and thus release the com objects) before
> shutting down the application.
>
> "Kevin Burton" <kevin.burton@avstarnews.com> wrote in message
> news:39d8d95a$1@news.devx.com...
> > I am getting a number of interface leaks from a simple C# application
that
> > uses a standard COM component. If I point Visual Studio Debug at the
> > compiled C# application and debug it the console shows a number of
> interface
> > leaks. I have included the C# source and the errors below. Any ideas
would
> > be greatly appreciated, or maybe I just need to wait for at least a beta
> > version. I don't get these leaks when using the COM component from
within
> > VBScript or JScript.
> >
> > Thank you.
> >
> > Kevin Burton
> > kevin.burton@inewsroom.com
>
>
>
-
Re: Interface leaks in C#?
I also tried to put
DestroyWindow();
m_hWnd = NULL;
in the destructor of my class. I no longer received the assert but I am
still getting the interface leaks.
Kevin
"Kevin Burton" <kevin.burton@avstarnews.com> wrote in message
news:39da0401$1@news.devx.com...
> Thank you for your suggestions. I tired adding
> GC.RequestFinalizeOnShutdown() at the top of 'Main' but now I am getting
an
> assertion "ATL: ERROR - Object deleted before windows was destroyed." This
> is happening in the CAnSignon class that implements the ISignon interface
> and also inherits from ATL::CWindowImpl to help with the connection
points.
> How do I destroy window before the object? A stack trace is included
below,
> maybe that helps.
>
> Kevin
>
> ATL::CWindowImplRoot<ATL::CWindow>::~CWindowImplRoot<ATL::CWindow>() line
> 1903 + 41 bytes
> ATL::CWindowImplBaseT<ATL::CWindow,ATL::CWinTraits<1442840576,0>
> >::~CWindowImplBaseT<ATL::CWindow,ATL::CWinTraits<1442840576,0> >() + 20
> bytes
> ATL::CWindowImpl<CAnSignon,ATL::CWindow,ATL::CWinTraits<1442840576,0>
> >::~CWindowImpl<CAnSignon,ATL::CWindow,ATL::CWinTraits<1442840576,0> >() +
> 20 bytes
> CAnSignon::~CAnSignon() line 156 + 243 bytes
> ATL::CComObject<CAnSignon>::~CComObject<CAnSignon>() line 2411 + 15 bytes
> ATL::CComObject<CAnSignon>::`scalar deleting destructor'(unsigned int
> 0x00000001) + 20 bytes
> ATL::CComObject<CAnSignon>::Release(ATL::CComObject<CAnSignon> * const
> 0x048e0a78) line 2419 + 31 bytes
> ATL::_QIThunk::Release(ATL::_QIThunk * const 0x048e0d50) line 2734
> BCCORE! 0c07be4c()
> MSCORWKS! 6d0a4ba0()
> MSCORWKS! 6d0a53b7()
> MSCORWKS! 6d054d7e
> "Jeff Peil" <jpeil@bigfoot.com> wrote in message
> news:39d8dac8$1@news.devx.com...
> > Kevin,
> >
> > For now I suggest you add a System.GC.RequestFinalizeOnShutdown() call
at
> > the top of your main method. Otherwise the garbage collector will not
> > attempt to finalize objects (and thus release the com objects) before
> > shutting down the application.
> >
> > "Kevin Burton" <kevin.burton@avstarnews.com> wrote in message
> > news:39d8d95a$1@news.devx.com...
> > > I am getting a number of interface leaks from a simple C# application
> that
> > > uses a standard COM component. If I point Visual Studio Debug at the
> > > compiled C# application and debug it the console shows a number of
> > interface
> > > leaks. I have included the C# source and the errors below. Any ideas
> would
> > > be greatly appreciated, or maybe I just need to wait for at least a
beta
> > > version. I don't get these leaks when using the COM component from
> within
> > > VBScript or JScript.
> > >
> > > Thank you.
> > >
> > > Kevin Burton
> > > kevin.burton@inewsroom.com
> >
> >
> >
>
>
-
Re: Interface leaks in C#?
Kevin,
This is probably over my head, but I'm interested so...
This error looks due to the fact that the GC doesn't finalize objects in any
particular order.
Another solution might be to use the Marshal.ReleaseComObject method in the
System.Runtime.InteropServices namespace, which releases a COM object
allowing you to tear down the object hierarchy in a "normal" manner.
Something like the following untested code...
using System;
using System.Collections;
using AvstarNRCSLib;
using System.Runtime.InteropServices;
class NRCS
{
static void Main()
{
Console.WriteLine("Hello, World");
ISignon signon = (ISignon)new __AnSignon();
signon.Signon("avstar", "avstar", "172.27.18.77", "", "");
if (signon.IsSignon() != 0)
{
Console.WriteLine("Signed on!");
IDirectory dir = (IDirectory)signon.get_Directory(".");
foreach(Object item in (IEnumerable)dir) {
if(item is IDirectory) {
IDirectory ld = (IDirectory)item;
Console.WriteLine(ld.Name + " Directory");
}
else if(item is IQueue) {
IQueue lq = (IQueue)item;
IStory lss;
int limit = 10000;
Console.WriteLine(lq.Name + " Queue");
if(lq.Name == "DEAD") {
limit = 100;
}
}
else if(item is IStory) {
IStory ls = (IStory)item;
Console.WriteLine(ls.Name + " Story");
}
// not sure if this is ok in the loop, <<<<<<<
// but try without it if not
Marshal.ReleaseComObject(item);
}
// finished with dir <<<<<<<
Marshal.ReleaseComObject(dir);
signon.Signoff();
// finished with signon <<<<<<<
Marshal.ReleaseComObject(signon);
}
else
{
Console.WriteLine("Error signing on!");
}
}
}
.... that may help with some of the Interface leaks, if not all. Let us know
how you get on.
--
David.
Kevin Burton <kevin.burton@avstarnews.com> wrote in message
news:39da0401$1@news.devx.com...
> Thank you for your suggestions. I tired adding
> GC.RequestFinalizeOnShutdown() at the top of 'Main' but now I am getting
an
> assertion "ATL: ERROR - Object deleted before windows was destroyed." This
> is happening in the CAnSignon class that implements the ISignon interface
> and also inherits from ATL::CWindowImpl to help with the connection
points.
> How do I destroy window before the object? A stack trace is included
below,
> maybe that helps.
>
> Kevin
>
-
Re: Interface leaks in C#?
This is getting closer. I removed the DestroyWindow() call and setting the
m_hWnd to NULL and I don't get any exceptions like I was with GC.Collect().
But I am still seeing interface leaks.
Kevin
"David Bayley" <dbayley@aebacus.com> wrote in message
news:39da1473@news.devx.com...
> Kevin,
>
> This is probably over my head, but I'm interested so...
>
> This error looks due to the fact that the GC doesn't finalize objects in
any
> particular order.
>
> Another solution might be to use the Marshal.ReleaseComObject method in
the
> System.Runtime.InteropServices namespace, which releases a COM object
> allowing you to tear down the object hierarchy in a "normal" manner.
>
> Something like the following untested code...
>
> using System;
> using System.Collections;
> using AvstarNRCSLib;
> using System.Runtime.InteropServices;
>
> class NRCS
> {
> static void Main()
> {
> Console.WriteLine("Hello, World");
> ISignon signon = (ISignon)new __AnSignon();
> signon.Signon("avstar", "avstar", "172.27.18.77", "", "");
>
> if (signon.IsSignon() != 0)
> {
> Console.WriteLine("Signed on!");
> IDirectory dir = (IDirectory)signon.get_Directory(".");
> foreach(Object item in (IEnumerable)dir) {
> if(item is IDirectory) {
> IDirectory ld = (IDirectory)item;
> Console.WriteLine(ld.Name + " Directory");
> }
> else if(item is IQueue) {
> IQueue lq = (IQueue)item;
> IStory lss;
> int limit = 10000;
> Console.WriteLine(lq.Name + " Queue");
> if(lq.Name == "DEAD") {
> limit = 100;
> }
> }
> else if(item is IStory) {
> IStory ls = (IStory)item;
> Console.WriteLine(ls.Name + " Story");
> }
> // not sure if this is ok in the loop, <<<<<<<
> // but try without it if not
> Marshal.ReleaseComObject(item);
> }
> // finished with dir <<<<<<<
> Marshal.ReleaseComObject(dir);
>
> signon.Signoff();
> // finished with signon <<<<<<<
> Marshal.ReleaseComObject(signon);
> }
> else
> {
> Console.WriteLine("Error signing on!");
> }
> }
> }
>
>
> ... that may help with some of the Interface leaks, if not all. Let us
know
> how you get on.
>
> --
> David.
>
>
>
> Kevin Burton <kevin.burton@avstarnews.com> wrote in message
> news:39da0401$1@news.devx.com...
> > Thank you for your suggestions. I tired adding
> > GC.RequestFinalizeOnShutdown() at the top of 'Main' but now I am getting
> an
> > assertion "ATL: ERROR - Object deleted before windows was destroyed."
This
> > is happening in the CAnSignon class that implements the ISignon
interface
> > and also inherits from ATL::CWindowImpl to help with the connection
> points.
> > How do I destroy window before the object? A stack trace is included
> below,
> > maybe that helps.
> >
> > Kevin
> >
>
>
>
>
>
-
Re: Interface leaks in C#?
Kevin,
When you say it's getting closer, is that because the interface leaks have
been reduced?
An additional line of attack might be to change the "foreach" loop to a
normal "for" loop using IDirectory.Count/Item (or equivalent) if they exist.
The reason being that I think that foreach uses the
IEnumerable.GetEnumerator method, which returns a new IEnumerator reference.
We have not ReleaseComObject'ed this reference. Alternatively, declare an
IEnumerator variable and set it to ((IEnumerable)dir).GetEnumerator(), then
foreach over that (or use MoveNext in a while loop if that doesn't work),
and after the loop call ReleaseComObject(yourEnumerator).
MS are working hard at COM Interpop, and I'm sure they would be interested
in the problems your having (I know I am). If the for loop doesn't work,
then try emailing one of the MS participants on msnews csharp.general
directly. Don't forget to let us know with any solutions ;-)
--
David.
Kevin Burton <kevin.burton@avstarnews.com> wrote in message
news:39da3023$1@news.devx.com...
> This is getting closer. I removed the DestroyWindow() call and setting the
> m_hWnd to NULL and I don't get any exceptions like I was with
GC.Collect().
> But I am still seeing interface leaks.
>
> Kevin
>
-
Re: Interface leaks in C#?
When I say it is getting closer I just mean that I no longer have to
explicitly call DestroyWindow and set the m_hWnd to NULL. Using
ReleaseComObject has just as many interface leaks it just doesn't add the
extra exception that GC.Collect() seems to add. Also a positive to using
ReleaseComObject is that OnFinalMessage gets called whereas with
GC.Collect() it does not. When I change the C# code to add an extra
variable 'IEnumerable it = (IEnumerable)dir' and specifically
ReleaseComObject on that I get an exception (InvalidCast) when I try to use
the 'dir'. Somehow the two seemed to be linked.
I created another interface that returns a SAFEARRAY instead of relying on
IEnumerable. When I enumerate through this I don't get any interface leaks.
So as you suspected it seems to be somehow related to IEnumerable not
getting released.
Kevin
"David Bayley" <dbayley@aebacus.com> wrote in message
news:39da3d52@news.devx.com...
> Kevin,
>
> When you say it's getting closer, is that because the interface leaks have
> been reduced?
>
> An additional line of attack might be to change the "foreach" loop to a
> normal "for" loop using IDirectory.Count/Item (or equivalent) if they
exist.
> The reason being that I think that foreach uses the
> IEnumerable.GetEnumerator method, which returns a new IEnumerator
reference.
> We have not ReleaseComObject'ed this reference. Alternatively, declare an
> IEnumerator variable and set it to ((IEnumerable)dir).GetEnumerator(),
then
> foreach over that (or use MoveNext in a while loop if that doesn't work),
> and after the loop call ReleaseComObject(yourEnumerator).
>
> MS are working hard at COM Interpop, and I'm sure they would be interested
> in the problems your having (I know I am). If the for loop doesn't work,
> then try emailing one of the MS participants on msnews csharp.general
> directly. Don't forget to let us know with any solutions ;-)
>
> --
> David.
>
>
> Kevin Burton <kevin.burton@avstarnews.com> wrote in message
> news:39da3023$1@news.devx.com...
> > This is getting closer. I removed the DestroyWindow() call and setting
the
> > m_hWnd to NULL and I don't get any exceptions like I was with
> GC.Collect().
> > But I am still seeing interface leaks.
> >
> > Kevin
> >
>
>
>
-
Re: Interface leaks in C#?
So where do i get a C# compiler and associated tools?
-
Re: Interface leaks in C#?
> So where do I get a C# compiler and associated tools?
Ellis: Go to http://msdn.microsoft.com/net/ and click on the link labeled,
"Download the .NET Framework SDK Technology Preview."
Or, purchase an MSDN Universal subscription, and Microsoft will send you a
copy of Beta 1 when it ships later this month:
http://msdn.microsoft.com/vstudio/nextgen/betaone.asp .
---
Phil Weber
-
Re: Interface leaks in C#?
If I change the C# to use for(i=0;i < dir.Count;i++)
instead of IEnumerator then I don't get any interface leaks.
Kevin Burton
kevin.burton@inewsroom.com
"David Bayley" <dbayley@aebacus.com> wrote in message
news:39da3d52@news.devx.com...
> Kevin,
>
> When you say it's getting closer, is that because the interface leaks have
> been reduced?
>
> An additional line of attack might be to change the "foreach" loop to a
> normal "for" loop using IDirectory.Count/Item (or equivalent) if they
exist.
> The reason being that I think that foreach uses the
> IEnumerable.GetEnumerator method, which returns a new IEnumerator
reference.
> We have not ReleaseComObject'ed this reference. Alternatively, declare an
> IEnumerator variable and set it to ((IEnumerable)dir).GetEnumerator(),
then
> foreach over that (or use MoveNext in a while loop if that doesn't work),
> and after the loop call ReleaseComObject(yourEnumerator).
>
> MS are working hard at COM Interpop, and I'm sure they would be interested
> in the problems your having (I know I am). If the for loop doesn't work,
> then try emailing one of the MS participants on msnews csharp.general
> directly. Don't forget to let us know with any solutions ;-)
>
> --
> David.
>
>
> Kevin Burton <kevin.burton@avstarnews.com> wrote in message
> news:39da3023$1@news.devx.com...
> > This is getting closer. I removed the DestroyWindow() call and setting
the
> > m_hWnd to NULL and I don't get any exceptions like I was with
> GC.Collect().
> > But I am still seeing interface leaks.
> >
> > Kevin
> >
>
>
>
-
Re: Interface leaks in C#?
Hey Kevin,
Have you tried creating a Managed Wrapper for the classic COM component?
This is probably the source of the problem There are a couple things you
have to do to use Unmanaged classic COM with .NET.
Try using the tlbimp.exe - Type Library Importer to convert the typlib into
.NET metadata. I think you will get better results! COM Interop is improved
in BETA from what I have heard.
Anyway hope this helps.
Don R. Wolthuis, MCSD
CodeJunkies.Net / ASPNextGen.com
"Kevin Burton" <kevin.burton@avstarnews.com> wrote:
>I am getting a number of interface leaks from a simple C# application that
>uses a standard COM component. If I point Visual Studio Debug at the
>compiled C# application and debug it the console shows a number of interface
>leaks. I have included the C# source and the errors below. Any ideas would
>be greatly appreciated, or maybe I just need to wait for at least a beta
>version. I don't get these leaks when using the COM component from within
>VBScript or JScript.
>
>Thank you.
>
>Kevin Burton
>kevin.burton@inewsroom.com
>
>using System;
>using System.Collections;
>using AvstarNRCSLib;
>
>class NRCS
>{
> static void Main()
> {
> Console.WriteLine("Hello, World");
> ISignon signon = (ISignon)new __AnSignon();
> signon.Signon("avstar", "avstar", "172.27.18.77", "", "");
>
> if (signon.IsSignon() != 0)
> {
> Console.WriteLine("Signed on!");
> IDirectory dir = (IDirectory)signon.get_Directory(".");
> foreach(Object item in (IEnumerable)dir) {
> if(item is IDirectory) {
> IDirectory ld = (IDirectory)item;
> Console.WriteLine(ld.Name + " Directory");
> }
> else if(item is IQueue) {
> IQueue lq = (IQueue)item;
> IStory lss;
> int limit = 10000;
> Console.WriteLine(lq.Name + " Queue");
> if(lq.Name == "DEAD") {
> limit = 100;
> }
> }
> else if(item is IStory) {
> IStory ls = (IStory)item;
> Console.WriteLine(ls.Name + " Story");
> }
> }
> signon.Signoff();
> }
> else
> {
> Console.WriteLine("Error signing on!");
> }
> }
>}
>
>INTERFACE LEAK: RefCount = 1, MaxRefCount = 4, {Allocation = 7}
>CAnDirectory - IUnknown
>INTERFACE LEAK: RefCount = 1, MaxRefCount = 2, {Allocation = 69}
>CAnDirectory - IDispatch
>NonAddRef Thunk LEAK: {Allocation = 70}
>INTERFACE LEAK: RefCount = 2, MaxRefCount = 2, {Allocation = 71} CAnQueue
-
>IDispatch
>NonAddRef Thunk LEAK: {Allocation = 72}
>INTERFACE LEAK: RefCount = 2, MaxRefCount = 2, {Allocation = 73}
>CAnDirectory - IDispatch
>NonAddRef Thunk LEAK: {Allocation = 74}
>INTERFACE LEAK: RefCount = 2, MaxRefCount = 2, {Allocation = 75}
>CAnDirectory - IDispatch
>NonAddRef Thunk LEAK: {Allocation = 76}
>INTERFACE LEAK: RefCount = 2, MaxRefCount = 2, {Allocation = 77}
>CAnDirectory - IDispatch
>NonAddRef Thunk LEAK: {Allocation = 78}
>INTERFACE LEAK: RefCount = 2, MaxRefCount = 2, {Allocation = 79} CAnQueue
-
>IDispatch
>NonAddRef Thunk LEAK: {Allocation = 80}
>INTERFACE LEAK: RefCount = 2, MaxRefCount = 2, {Allocation = 81}
>CAnDirectory - IDispatch
>NonAddRef Thunk LEAK: {Allocation = 82}
>INTERFACE LEAK: RefCount = 2, MaxRefCount = 2, {Allocation = 83} CAnQueue
-
>IDispatch
>NonAddRef Thunk LEAK: {Allocation = 84}
>INTERFACE LEAK: RefCount = 2, MaxRefCount = 2, {Allocation = 85} CAnQueue
-
>IDispatch
>NonAddRef Thunk LEAK: {Allocation = 86}
>INTERFACE LEAK: RefCount = 2, MaxRefCount = 2, {Allocation = 87} CAnQueue
-
>IDispatch
>NonAddRef Thunk LEAK: {Allocation = 88}
>INTERFACE LEAK: RefCount = 2, MaxRefCount = 2, {Allocation = 89}
>CAnDirectory - IDispatch
>NonAddRef Thunk LEAK: {Allocation = 90}
>INTERFACE LEAK: RefCount = 2, MaxRefCount = 2, {Allocation = 91}
>CAnDirectory - IDispatch
>NonAddRef Thunk LEAK: {Allocation = 92}
>INTERFACE LEAK: RefCount = 2, MaxRefCount = 2, {Allocation = 93}
>CAnDirectory - IDispatch
>NonAddRef Thunk LEAK: {Allocation = 94}
>INTERFACE LEAK: RefCount = 2, MaxRefCount = 2, {Allocation = 95}
>CAnDirectory - IDispatch
>NonAddRef Thunk LEAK: {Allocation = 96}
>INTERFACE LEAK: RefCount = 2, MaxRefCount = 2, {Allocation = 97}
>CAnDirectory - IDispatch
>NonAddRef Thunk LEAK: {Allocation = 98}
>INTERFACE LEAK: RefCount = 2, MaxRefCount = 2, {Allocation = 99}
>CAnDirectory - IDispatch
>NonAddRef Thunk LEAK: {Allocation = 100}
>INTERFACE LEAK: RefCount = 2, MaxRefCount = 2, {Allocation = 101}
>CAnDirectory - IDispatch
>NonAddRef Thunk LEAK: {Allocation = 102}
>INTERFACE LEAK: RefCount = 2, MaxRefCount = 2, {Allocation = 103}
>CAnDirectory - IDispatch
>NonAddRef Thunk LEAK: {Allocation = 104}
>INTERFACE LEAK: RefCount = 2, MaxRefCount = 2, {Allocation = 105}
>CAnDirectory - IDispatch
>NonAddRef Thunk LEAK: {Allocation = 106}
>INTERFACE LEAK: RefCount = 2, MaxRefCount = 2, {Allocation = 107}
>CAnDirectory - IDispatch
>NonAddRef Thunk LEAK: {Allocation = 108}
>INTERFACE LEAK: RefCount = 2, MaxRefCount = 2, {Allocation = 109}
>CAnDirectory - IDispatch
>NonAddRef Thunk LEAK: {Allocation = 110}
>INTERFACE LEAK: RefCount = 2, MaxRefCount = 2, {Allocation = 111}
>CAnDirectory - IDispatch
>NonAddRef Thunk LEAK: {Allocation = 112}
>INTERFACE LEAK: RefCount = 2, MaxRefCount = 2, {Allocation = 113}
>CAnDirectory - IDispatch
>NonAddRef Thunk LEAK: {Allocation = 114}
>INTERFACE LEAK: RefCount = 2, MaxRefCount = 2, {Allocation = 115}
>CAnDirectory - IDispatch
>NonAddRef Thunk LEAK: {Allocation = 116}
>INTERFACE LEAK: RefCount = 2, MaxRefCount = 2, {Allocation = 117} CAnQueue
-
>IDispatch
>NonAddRef Thunk LEAK: {Allocation = 118}
>INTERFACE LEAK: RefCount = 2, MaxRefCount = 2, {Allocation = 119} CAnQueue
-
>IDispatch
>NonAddRef Thunk LEAK: {Allocation = 120}
>INTERFACE LEAK: RefCount = 2, MaxRefCount = 2, {Allocation = 121} CAnQueue
-
>IDispatch
>NonAddRef Thunk LEAK: {Allocation = 122}
>INTERFACE LEAK: RefCount = 2, MaxRefCount = 2, {Allocation = 123}
>CAnDirectory - IDispatch
>INTERFACE LEAK: RefCount = 1, MaxRefCount = 2, {Allocation = 124}
>_CComEnum - IUnknown
>INTERFACE LEAK: RefCount = 2, MaxRefCount = 2, {Allocation = 125}
>_CComEnum - IEnumVARIANT
>
>
>
>
>
-
Re: Interface leaks in C#?
I am using tlbimp, otherwise the code would not compile. Notice the 'using
AvstarNRCSLib;' line below. Maybe I just need to wait for the BETA.
Kevin
"Don R. Wolthuis" <don.wolthuis@codejunkies.net> wrote in message
news:39dd9391$1@news.devx.com...
>
> Hey Kevin,
>
> Have you tried creating a Managed Wrapper for the classic COM component?
> This is probably the source of the problem There are a couple things you
> have to do to use Unmanaged classic COM with .NET.
>
> Try using the tlbimp.exe - Type Library Importer to convert the typlib
into
> NET metadata. I think you will get better results! COM Interop is
improved
> in BETA from what I have heard.
>
> Anyway hope this helps.
>
> Don R. Wolthuis, MCSD
> CodeJunkies.Net / ASPNextGen.com
>
>
>
> "Kevin Burton" <kevin.burton@avstarnews.com> wrote:
> >I am getting a number of interface leaks from a simple C# application
that
> >uses a standard COM component. If I point Visual Studio Debug at the
> >compiled C# application and debug it the console shows a number of
interface
> >leaks. I have included the C# source and the errors below. Any ideas
would
> >be greatly appreciated, or maybe I just need to wait for at least a beta
> >version. I don't get these leaks when using the COM component from within
> >VBScript or JScript.
> >
> >Thank you.
> >
> >Kevin Burton
> >kevin.burton@inewsroom.com
> >
> >using System;
> >using System.Collections;
> >using AvstarNRCSLib;
> >
> >class NRCS
> >{
> > static void Main()
> > {
> > Console.WriteLine("Hello, World");
> > ISignon signon = (ISignon)new __AnSignon();
> > signon.Signon("avstar", "avstar", "172.27.18.77", "", "");
> >
> > if (signon.IsSignon() != 0)
> > {
> > Console.WriteLine("Signed on!");
> > IDirectory dir = (IDirectory)signon.get_Directory(".");
> > foreach(Object item in (IEnumerable)dir) {
> > if(item is IDirectory) {
> > IDirectory ld = (IDirectory)item;
> > Console.WriteLine(ld.Name + " Directory");
> > }
> > else if(item is IQueue) {
> > IQueue lq = (IQueue)item;
> > IStory lss;
> > int limit = 10000;
> > Console.WriteLine(lq.Name + " Queue");
> > if(lq.Name == "DEAD") {
> > limit = 100;
> > }
> > }
> > else if(item is IStory) {
> > IStory ls = (IStory)item;
> > Console.WriteLine(ls.Name + " Story");
> > }
> > }
> > signon.Signoff();
> > }
> > else
> > {
> > Console.WriteLine("Error signing on!");
> > }
> > }
> >}
> >
> >INTERFACE LEAK: RefCount = 1, MaxRefCount = 4, {Allocation = 7}
> >CAnDirectory - IUnknown
> >INTERFACE LEAK: RefCount = 1, MaxRefCount = 2, {Allocation = 69}
> >CAnDirectory - IDispatch
> >NonAddRef Thunk LEAK: {Allocation = 70}
> >INTERFACE LEAK: RefCount = 2, MaxRefCount = 2, {Allocation = 71} CAnQueue
> -
> >IDispatch
> >NonAddRef Thunk LEAK: {Allocation = 72}
> >INTERFACE LEAK: RefCount = 2, MaxRefCount = 2, {Allocation = 73}
> >CAnDirectory - IDispatch
> >NonAddRef Thunk LEAK: {Allocation = 74}
> >INTERFACE LEAK: RefCount = 2, MaxRefCount = 2, {Allocation = 75}
> >CAnDirectory - IDispatch
> >NonAddRef Thunk LEAK: {Allocation = 76}
> >INTERFACE LEAK: RefCount = 2, MaxRefCount = 2, {Allocation = 77}
> >CAnDirectory - IDispatch
> >NonAddRef Thunk LEAK: {Allocation = 78}
> >INTERFACE LEAK: RefCount = 2, MaxRefCount = 2, {Allocation = 79} CAnQueue
> -
> >IDispatch
> >NonAddRef Thunk LEAK: {Allocation = 80}
> >INTERFACE LEAK: RefCount = 2, MaxRefCount = 2, {Allocation = 81}
> >CAnDirectory - IDispatch
> >NonAddRef Thunk LEAK: {Allocation = 82}
> >INTERFACE LEAK: RefCount = 2, MaxRefCount = 2, {Allocation = 83} CAnQueue
> -
> >IDispatch
> >NonAddRef Thunk LEAK: {Allocation = 84}
> >INTERFACE LEAK: RefCount = 2, MaxRefCount = 2, {Allocation = 85} CAnQueue
> -
> >IDispatch
> >NonAddRef Thunk LEAK: {Allocation = 86}
> >INTERFACE LEAK: RefCount = 2, MaxRefCount = 2, {Allocation = 87} CAnQueue
> -
> >IDispatch
> >NonAddRef Thunk LEAK: {Allocation = 88}
> >INTERFACE LEAK: RefCount = 2, MaxRefCount = 2, {Allocation = 89}
> >CAnDirectory - IDispatch
> >NonAddRef Thunk LEAK: {Allocation = 90}
> >INTERFACE LEAK: RefCount = 2, MaxRefCount = 2, {Allocation = 91}
> >CAnDirectory - IDispatch
> >NonAddRef Thunk LEAK: {Allocation = 92}
> >INTERFACE LEAK: RefCount = 2, MaxRefCount = 2, {Allocation = 93}
> >CAnDirectory - IDispatch
> >NonAddRef Thunk LEAK: {Allocation = 94}
> >INTERFACE LEAK: RefCount = 2, MaxRefCount = 2, {Allocation = 95}
> >CAnDirectory - IDispatch
> >NonAddRef Thunk LEAK: {Allocation = 96}
> >INTERFACE LEAK: RefCount = 2, MaxRefCount = 2, {Allocation = 97}
> >CAnDirectory - IDispatch
> >NonAddRef Thunk LEAK: {Allocation = 98}
> >INTERFACE LEAK: RefCount = 2, MaxRefCount = 2, {Allocation = 99}
> >CAnDirectory - IDispatch
> >NonAddRef Thunk LEAK: {Allocation = 100}
> >INTERFACE LEAK: RefCount = 2, MaxRefCount = 2, {Allocation = 101}
> >CAnDirectory - IDispatch
> >NonAddRef Thunk LEAK: {Allocation = 102}
> >INTERFACE LEAK: RefCount = 2, MaxRefCount = 2, {Allocation = 103}
> >CAnDirectory - IDispatch
> >NonAddRef Thunk LEAK: {Allocation = 104}
> >INTERFACE LEAK: RefCount = 2, MaxRefCount = 2, {Allocation = 105}
> >CAnDirectory - IDispatch
> >NonAddRef Thunk LEAK: {Allocation = 106}
> >INTERFACE LEAK: RefCount = 2, MaxRefCount = 2, {Allocation = 107}
> >CAnDirectory - IDispatch
> >NonAddRef Thunk LEAK: {Allocation = 108}
> >INTERFACE LEAK: RefCount = 2, MaxRefCount = 2, {Allocation = 109}
> >CAnDirectory - IDispatch
> >NonAddRef Thunk LEAK: {Allocation = 110}
> >INTERFACE LEAK: RefCount = 2, MaxRefCount = 2, {Allocation = 111}
> >CAnDirectory - IDispatch
> >NonAddRef Thunk LEAK: {Allocation = 112}
> >INTERFACE LEAK: RefCount = 2, MaxRefCount = 2, {Allocation = 113}
> >CAnDirectory - IDispatch
> >NonAddRef Thunk LEAK: {Allocation = 114}
> >INTERFACE LEAK: RefCount = 2, MaxRefCount = 2, {Allocation = 115}
> >CAnDirectory - IDispatch
> >NonAddRef Thunk LEAK: {Allocation = 116}
> >INTERFACE LEAK: RefCount = 2, MaxRefCount = 2, {Allocation = 117}
CAnQueue
> -
> >IDispatch
> >NonAddRef Thunk LEAK: {Allocation = 118}
> >INTERFACE LEAK: RefCount = 2, MaxRefCount = 2, {Allocation = 119}
CAnQueue
> -
> >IDispatch
> >NonAddRef Thunk LEAK: {Allocation = 120}
> >INTERFACE LEAK: RefCount = 2, MaxRefCount = 2, {Allocation = 121}
CAnQueue
> -
> >IDispatch
> >NonAddRef Thunk LEAK: {Allocation = 122}
> >INTERFACE LEAK: RefCount = 2, MaxRefCount = 2, {Allocation = 123}
> >CAnDirectory - IDispatch
> >INTERFACE LEAK: RefCount = 1, MaxRefCount = 2, {Allocation = 124}
> >_CComEnum - IUnknown
> >INTERFACE LEAK: RefCount = 2, MaxRefCount = 2, {Allocation = 125}
> >_CComEnum - IEnumVARIANT
> >
> >
> >
> >
> >
>
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Development Centers
-- Android Development Center
-- Cloud Development Project Center
-- HTML5 Development Center
-- Windows Mobile Development Center
|