Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / Interop / September 2004

Tip: Looking for answers? Try searching our database.

Issue: Queued Component and Marshal.ReleaseComObject

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Invalidlastname - 30 Aug 2004 23:36 GMT
Hi,
We used .NET EnterpriseServices Queued components in our application to for certain asynchronous processes (code fragments was attached)
However, we found out that the "Objects", "Activated" counts in the Component Services MMC are growing constantly.
The application is running on Windows Server 2003 with .NET 1.1 framework. I found some discussion threads from google search

http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&threadm¶cc0fd6.0401080752.718
eb13%40posting.google.com&rnum=1&prev=/groups%3Fhl%3Den%26lr%3D%26ie%3DUTF-8%26s
elm%3Db6cc0fd6.0401080752.718eb13%2540posting.google.com


From this discussion, it looks like a known bug in the .NET while using queued components.
(another discussion is sort of related http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&threadme11286.0303130854.34c
4293b%40posting.google.com&rnum=1&prev=/groups%3Fhl%3Den%26lr%3D%26ie%3DUTF-8%26
selm%3D1ee11286.0303130854.34c4293b%2540posting.google.com
 )

I also found a KB Q article http://support.microsoft.com/?kbid‚6915 which may be related. (because the article does mention that it applies to .NET 1.0 and does not say anything about .NET 1.1 running on Windows 2k3 server) I am very interested to know has anyone applied the patch mentioned in the Q article and resolved the issue?

I really appreciate that if anyone can give me some suggestions, or point me what I did wrong using the queued components.

If this is a bug, is there any patch available and where I can download the catch?

Thanks

ILN

sample code of using queued components

///////////////////////////////////////////////////////////

IAsyncAgent agent = null;

try

{

   string sClsPath = "queue:/new:XXX" ;

   agent = (Agents.IAsyncAgent) Marshal.BindToMoniker(sClsPath);

   agent.xxx();

}

catch(Exception ex)

{

   ...

}

finally

{

   while(agent!=null && Marshal.ReleaseComObject(agent) > 0) {}

   agent = null;

}

///////////////////////////////////////////////////////////
"Peter Huang" - 31 Aug 2004 09:53 GMT
Hi,

Based on my knowledge, the KB article is just applied to .net framework
1.0, and will not applied to 1.1.
For your problem, is it specifed to the queued components, if you did not
enable the queued component feature, did the problem persists?
Also what did you do you in  agent.xxx(), you may try to simplify it, e.g.
just call debug.writeline.
Is there any other application is using the queued component?
You may try to test with one application  to call the queued component,
also you may try to call code below  after set the agent to null in the
finalize block.

        GC.Collect()
        GC.WaitForPendingFinalizers()
        GC.Collect()
        GC.WaitForPendingFinalizers()

you may have a try and let me know the result.

Best regards,

Peter Huang
Microsoft Online Partner Support

Signature

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.

Invalidlastname - 31 Aug 2004 18:08 GMT
Peter,
Thanks for the quick response. I have tried all your suggestions and none of
them worked in my case.

In your best knowledge, is this is an issue of using queued component in
.NET? If this is an issue, is there any fix or workaround available?

> Hi,
>
> Based on my knowledge, the KB article is just applied to .net framework
> 1.0, and will not applied to 1.1.

Just try to clarify it. Are you saying that such issue has been fixed in the
.NET 1.1 ?

> For your problem, is it specifed to the queued components, if you did not
> enable the queued component feature, did the problem persists?

If I used Marshal.BindToMoniker("new:XXX") to create the object, then I got
the same issue as I used it as queued component. However, if I used "new" to
create object then call Dispose when the process finished, the "Objects" and
"Activated" will remain 0 (The COM+ application will be activated, but all
counts in MMC remain 0)

> Also what did you do you in  agent.xxx(), you may try to simplify it, e.g.
> just call debug.writeline.
I comments out all the code in the method, and there was no change for the
behavior

> Is there any other application is using the queued component?
The answer is no.

> You may try to test with one application  to call the queued component,
> also you may try to call code below  after set the agent to null in the
[quoted text clipped - 4 lines]
>          GC.Collect()
>          GC.WaitForPendingFinalizers()
I did see this solution as a workaround from several newsgroup threads. I
tried it, surprisingly, it DID NOT work either

> you may have a try and let me know the result.
>
[quoted text clipped - 5 lines]
> Get Secure! - www.microsoft.com/security
> This posting is provided "AS IS" with no warranties, and confers no rights.
"Peter Huang" - 01 Sep 2004 03:55 GMT
Hi,

I will keep researching the issue and update you with new information ASAP.

Best regards,

Peter Huang
Microsoft Online Partner Support

Signature

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.

"Peter Huang" - 02 Sep 2004 08:25 GMT
Hi,

I have comfirm with our senior engineer that KB's bug will not apply here.
About the QC issue, you are probably not overriding Dispose in that
IAsyncAgent i/f (I assume that is your interface?).
e.g.

[Server]
using System.Reflection;
using System.EnterpriseServices;
using System;
[assembly: ApplicationName("QCDemoSvr")]
[assembly: ApplicationActivation(ActivationOption.Server)]
[assembly: ApplicationQueuing(Enabled=true, QueueListenerEnabled=true)]

namespace QCDemo
{
    public interface IQComponent
    {
        void DisplayMessage(string msg);
        void Dispose();
    }

    [InterfaceQueuing(Interface = "IQComponent"),EventTrackingEnabled(true)]
    public class QComponent  : ServicedComponent, IQComponent
    {
        public void DisplayMessage(string msg)
        {
            System.Diagnostics.Debug.WriteLine(msg+ "Processing message");
        }
    }
}

[client]
private void button1_Click(object sender, System.EventArgs e)
{
    IQComponent iQc = null;
    try
    {
        iQc = (IQComponent)Marshal.BindToMoniker("queue:/new:QCDemo.QComponent");
    }
    catch
    {
        MessageBox.Show("Cannot create Queued Component");
    }
    Debug.WriteLine("Send Message");
    iQc.DisplayMessage (this.textBox1.Text);
    iQc.Dispose(); //Call Dispose here
    Marshal.ReleaseComObject(iQc);
}   

Best regards,

Peter Huang
Microsoft Online Partner Support

Signature

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.

Invalidlastname - 02 Sep 2004 23:19 GMT
Peter,
Thanks for helps and you have resolved my issue =)
Now the "Objects" and "Activated" counts go back to 0 when the calls
completed.

I think the trick part is to know the correct order of methods, which
release the references of the objects, should be called.
Originally I have my interface inherit the IDisposable and I got
"QueryInterface for interface System.IDisposable failed." and I didn't come
up the ideal to explicitly define the Dispose() method in the interface, so
the client program can call the dispose method before the
Marshal.ReleaseComObject()

Anyway, I cannot thank you more for the helps you provided. It would be very
helpful to see MSDN documents cover such valuable information, such as <
call Dispose() here =)

Rgds,

ILN

> Hi,
>
[quoted text clipped - 54 lines]
> Get Secure! - www.microsoft.com/security
> This posting is provided "AS IS" with no warranties, and confers no rights.
"Peter Huang" - 03 Sep 2004 02:28 GMT
Hi,

I am glad that the problem has been resolved.

Cheers!

Best regards,

Peter Huang
Microsoft Online Partner Support

Signature

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.

Invalidlastname - 03 Sep 2004 20:51 GMT
Peter,
one last question. I am just curious why I got the following exception if I make the interface inherit the IDisposable instead of having Dispose() explicitly defined in the interface ?
System.InvalidCastException: QueryInterface for interface System.IDisposable failed.

at System.IDisposable.Dispose()

// Code Snippets ===========================
// Interface

public interface IAsyncAgent : IDisposable

{

...

//void Dispose();    // remove this line since the interface itself inherits the IDisposable

}

//client
Agents.IAsyncAgent agent = null;

agent.Dispose();    //<<<error occurred. System.InvalidCastException: QueryInterface for interface System.IDisposable failed.

while(Marshal.ReleaseComObject(agent) > 0) {}

agent = null;

> Hi,
>
[quoted text clipped - 9 lines]
> Get Secure! - www.microsoft.com/security
> This posting is provided "AS IS" with no warranties, and confers no rights.
"Peter Huang" - 06 Sep 2004 09:43 GMT
Hi,

From the TLB file generated by the QC, IAsyncAgent is derived from
IDispatch not from IDispose, the QI will failed.

Best regards,

Peter Huang
Microsoft Online Partner Support

Signature

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.


Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.