Unexpected Exceptions in SQL/COM+ Since Converting to VS 2005

We are running a COM+ DLL that handles transactions and security with a SQL Server back-end.  This project was started in VS 2003, but we just converted it to VS 2005.  Since the conversion, creating a number of transactions in a row generates errors at consistent, but moving, locations in the code (i.e. the location where the failure occurs changes when I do things such as add additional try/catch statements, so it is not random but also clearly not associated with any particular line of code).

In the application, the error appears as follows:
-------
System.InvalidCastException was unhandled
  Message="Unable to cast COM object of type 'System.__ComObject' to interface type 'System.IDisposable'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{805D7A98-D4AF-3F0F-967F-E5CF45312D2C}' failed due to the following error: COM+ activation failed because the activation could not be completed in the specified amount of time. (Exception from HRESULT: 0x8004E024)."
  Source="mscorlib"
  StackTrace:
    Server stack trace:
       at System.IDisposable.Dispose()
       at System.Runtime.Remoting.Messaging.StackBuilderSink._PrivateProcessMessage(IntPtr md, Object[] args, Object server, Int32 methodPtr, Boolean fExecuteInContext, Object[]& outArgs)
       at System.Runtime.Remoting.Messaging.StackBuilderSink.PrivateProcessMessage(RuntimeMethodHandle md, Object[] args, Object server, Int32 methodPtr, Boolean fExecuteInContext, Object[]& outArgs)
       at System.Runtime.Remoting.Messaging.StackBuilderSink.SyncProcessMessage(IMessage msg, Int32 methodPtr, Boolean fExecuteInContext)
    Exception rethrown at [0]:
       at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
       at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
       at System.IDisposable.Dispose()
       at MyDataTest.FormMain.GenerateLargeAssociation() in C:\Katana\Projects\Reserves Plus ASP\Testing\RPlusDataTest\FormMain.cs:line 560
       at RPlusDataTest.FormMain.btnEvil_Click_1(Object sender, EventArgs e) in C:\Katana\Projects\Reserves Plus ASP\Testing\RPlusDataTest\FormMain.cs:line 467
       at System.Windows.Forms.Control.OnClick(EventArgs e)
       at System.Windows.Forms.Button.OnClick(EventArgs e)
       at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
       at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
       at System.Windows.Forms.Control.WndProc(Message& m)
       at System.Windows.Forms.ButtonBase.WndProc(Message& m)
       at System.Windows.Forms.Button.WndProc(Message& m)
       at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
       at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
       at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
       at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
       at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
       at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
       at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
       at System.Windows.Forms.Application.Run(Form mainForm)
       at RPlusDataTest.FormMain.Main() in C:\Katana\Projects\Reserves Plus ASP\Testing\RPlusDataTest\FormMain.cs:line 579
       at System.AppDomain.nExecuteAssembly(Assembly assembly, String[] args)
       at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
       at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ThreadHelper.ThreadStart()
--------

This code worked fine before converting to VS 2005, so the error appears to be part of .NET Framework 2.0.  I have changed the following timeouts to no avail:
-- SQL Connection Timeout (in connection string)
-- SQL Lifetime Timeout (in connection string)
-- Transaction Timeout for COM+ (Component Services, My Computer, Properties)
-- Transaction Timeout for the individual COM+ component, as specified in the [Transaction(...)] attribute in C#.
-- Creation Timeout for the individual COM+ component, as specified in the [ObjectPooling(...)] attribute in C#.

Here's the SQL Connection string we're using:
Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=MyDB;Data Source=.;Connection Timeout=30;Connection Lifetime=60;Pooling=True
(Both timeouts were recently doubled, but made no visible difference.)

I have carefully verified that all COM+ objects being created are also being disposed of.  In fact, all COM+ object creations are in "using(...)" statements so the disposal will be carried out automatically by C#.

Just to be sure this point is clear: I can use my COM+ object to save about 10 times, and then I get this error.  The exact number of times involved varies.  (10 seemed like a convenient number, since it is also the maximum pool size, but changing that value did not alter anything.)

I also am getting event-log listings like the following.  They seem to be occuring at the same time as the other error:
---------
A condition has occurred that indicates this COM+ application is in an unstable state or is not functioning correctly. Assertion Failure: m_pTxResPool == NULL

Server Application ID: {BEA5C2EB-FCE6-4714-9C83-7D7D1E5DDA2D}

Server Application Instance ID:

{837A856B-3C40-45A9-BE2A-63B8A4B5BE71}

Server Application Name: RPlusData

The serious nature of this error has caused the process to terminate.

COM+ Services Internals Information:

File: d:\qxp_slp\com\com1x\src\comsvcs\txprop\txstream.cpp, Line: 608

Comsvcs.dll file version: ENU 2001.12.4414.308 shp

----------

Other notes: COM+ Server activiation, with object pooling and JITA, Transaction support for this object is required but we get the error on reads (no transaction) as well.

Update: This has now been turned over to Microsoft as a Technical Support Incident.  At present, no fix is available but they are reviewing information gathered from our systems.




Answer this question

Unexpected Exceptions in SQL/COM+ Since Converting to VS 2005

  • Arcadhia

    I just had a com+ component that uses object pooling begin to fail with this error. I implemented this code in CanBePooled() and the problem was resolved. I suspect that the latest security update for Windows XP (KB925902) installed on 4/3/07 may be the culprit.
  • LarryETL

    sorry, i can't.

    but it seems that there is a bug in framework 2.0. there went something wrong with the reference counter of the com+ objects...i think... :-/

    after a long try/error period we found a "solution" that is working:

    in the com+ project we overload the "CanBePooled()"-Method and simply holding a reference to the "ContextUtil.Transaction" object. now the reference-count seems to be ok, because no error occurs :-)

    here is the complete method:

    protected override bool CanBePooled()
    {

    // this line fixes the problem
    object o = ContextUtil.Transaction;


    if (ContextUtil.IsInTransaction)
    {
    return false;
    }
    else
    {
    return true;
    }
    }


  • Wesele

    I am experiencing the same issue.  When trying to connect to any other data base usintg any other technique, I get the same exact error message and am no longer capable of establishing connection to any data base that we previously used for vb2003.  Please keep me informed of the progress of this item.

    Thanks

    Don Clark
    clarkdjcr@hotmail.com


  • shama

    This issue was turned over to Microsoft as a technical support incident, and the result was a "private fix" for Windows XP.  You should be able to discuss this with Microsoft by referencing case number SRX051111604907.

    The upshot is that an error appears to exist in comsvcs.dll on the XP platform.  So far, our testing indicates that this patch (a new version of comsvcs.dll) solves the problem.  According to Microsoft, this fix should not be necessary for other O/S; our testing has so far been limited to XP platforms so we are unable to comment one way or the other.

    Good luck!

  • SDR_Ar

    Sorry, I don't; the private fix worked for us. Good luck!

  • ChrisBryan

    hi, i have exactly the same problem...

    i, got this private fix from microsoft, but it didn't work. i found another thread about a very similar problem. they said, that it probably has to do with pooling of com+ services... but it didn't...

    any further ideas


  • vsone

    I am having this problem also. I am in the process of getting Microsoft to send me the fix. Can anyone confirm for me that this for sure does not effect Windows 2003 Server


  • Unexpected Exceptions in SQL/COM+ Since Converting to VS 2005