Thursday, January 11, 2007

client application - intermittently receiving an error

A client application may intermittently receive an error message when a client application tries to create a COM+ component
View products that this article applies to.
Article ID : 911359
Last Review : January 20, 2006
Revision : 2.0


SYMPTOMS
When a client application tries to create a Microsoft COM+ component, the client application may intermittently receive an error message. Microsoft C++ applications may receive the following error message:
E_INVALIDARG: "The parameter is incorrect" (0x80070057/-2147024809)
Microsoft Visual Basic 6.0 applications may receive the following error message:
Run-time error '5': "Invalid procedure call or argument" (0x800a0005/-2146828283)
Client applications that are built on the Microsoft .NET Framework may receive the following error message:
System.ArgumentException: "The parameter is incorrect." at System.Runtime.Type.CreateInstanceImpl(Boolean publicOnly) at System.Activator.CreateInstance(Type type, Boolean nonPublic) (with _HResult = 0x80070057/-2147024809)
The COM+ application will typically function without error for some time immediately after the COM+ application is opened. The problem occurs intermittently, but increases in frequency over time until the application eventually fails on every activation request.

Note When the client application is running on a remote computer, the following error message is logged in the system event log on the client computer:
Event Type: Error
Event Source: DCOM
Event Category: None
Event ID: 10006
Description:
DCOM got error "One or more arguments are invalid " from the computer SERVERNAME when attempting to activate the server: GUID

Back to the top

CAUSE
This problem occurs because the "COM initialization count" for a thread is incremented and decremented when the CoInitialize function and the CoUninitialize function are called. When this count reaches zero after you call the CoUninitialize function, COM will be uninitialized on the thread. When a COM+ STA ThreadPool thread is uninitialized, the thread's apartment activator is destroyed. The next activation request that is routed to this thread will fail with the E_INVALIDARG error message. This problem occurs because the thread apartment activator is no longer available. Only activation requests that are routed to the particular uninitialized thread will fail. As more COM+ ThreadPool threads become uninitialized, a larger percentage of requests will fail. When all COM+ ThreadPool threads become uninitialized, all requests will fail. If the process is restarted, the problem will recover for some time. However, the cycle will be repeated.
Back to the top

RESOLUTION
To resolve this problem, remove the CoInitialize calls and the CoUninitialize calls from the affected COM DLL. A COM DLL that exposes COM components and is loaded through COM calls from a client should not call the CoInitialize function or the CoUninitialize function on any thread that is used to load or to start the DLL. These threads are owned by the client application, by the COM runtime, or by the COM+ runtime. Only the COM DLL should call these APIs on additional threads that were explicitly created by the COM DLL. However, it is a common bug for COM DLLs to call the CoInitialize function and the CoUninitialize function in response to attach events and detach events in the DllMain function.

Note It is correct for a standard Win32 DLL that is not loaded through COM to call these APIs if the standard Win32 DLL plans to use COM APIs. However, these functions should not be called from the DllMain function.

For more information about the CoInitialize function, visit the following Microsoft Developer Network (MSDN) Web site:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/com/html/0f171cf4-87b9-43a6-97f2-80ed344fe376.asp (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/com/html/0f171cf4-87b9-43a6-97f2-80ed344fe376.asp)
For more information about the DllMain function, visit the following MSDN Web site:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dllproc/base/dllmain.asp (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dllproc/base/dllmain.asp)
Note One Microsoft component that contains this bug is the Cdo.dll component. This component is not supported in multithreaded environments. Instead, we recommend that you use the Cdosys.dll component or the Cdonts.dll component. For more information, click the following article number to view the article in the Microsoft Knowledge Base:
247288 (http://support.microsoft.com/kb/247288/) CDO applications are not supported in MTS or COM+

No comments: