I think you are on the right track with apartments. But just
running your code in _an_ STA will not make it run in
_the_ STA in which the MMC interface pointer is
valid. Cross-apartment calls (between the MTA and an
STA, but also between STAs) need proxying (except
for free-threaded objects, etc.). My guess is that
IConsoleNamespace2 is not proxyable and therefore
the QueryInterface call fails trying to transport it
through the apartment boundary.

If this is the case, you will need to find a way to call
IConsoleNamespace2 methods from its apartment,
probably by calling to one of your objects living in
the same apartment.

Hope this helps,
--Jonathan

----- Original Message -----
From: "Raja" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Saturday, October 04, 2003 3:37 PM
Subject: [lists] [ADVANCED-DOTNET] QueryInterface() failed problem


> However, when I create a Timer(System.Threading.Timer or
> System.Timers.Timer) inside MySnapin class and I access myObject (by
> casting it to IConsoleNamespace2) within the timer-callback method--I get
> an exception with the following message:
>
> QueryInterface for interface IConsoleNamespace2 failed.
>
> Things I have tried so far but have not worked:
> 1) When I WriteLine() ApartmentState for MMC main thread, it gives me STA
> inside Initialize(). So I concluded that MMC is running in STA.
> 2) When I WriteLine() ApartmentState for Timer callback method, that
> thread gives me MTA which is okay as all Timer callbacks are using
> Threadpool threads and these are MTA by nature.
>
> 3) So with an assumption that it is an Apartment-mismatch, I took out
> Timer from mySnapin code and created a Thread and specifically set the
> apartment state to STA, but still the Thread-method gives the same error
> when it accesses the myobject. It did not work forcing me to think that it
> is not an apartment issue.

===================================
This list is hosted by DevelopMentor®  http://www.develop.com
NEW! ASP.NET courses you may be interested in:

2 Days of ASP.NET, 29 Sept 2003, in Redmond
http://www.develop.com/courses/2daspdotnet

Guerrilla ASP.NET, 13 Oct 2003, in Boston
http://www.develop.com/courses/gaspdotnet

View archives and manage your subscription(s) at http://discuss.develop.com

Reply via email to