Freigeben über


CLR SPY and Customer Debug Probes: The QueryInterface Failure Probe

It has taken awhile, but with this entry I will have described all 11 probes that exist in v1.1 of the CLR.

When an RCW queries its underlying COM object for a specific interface, the QueryInterface call could fail for a variety of reasons.  The QueryInterface Failure probe doesn't report every failed QI call as you might expect, but it isolates a specific cause of failure: when an interface cannot be marshaled to the current context.  When this happens, this probe emits a warning like the following:

Failed to QI for interface IMyInterface because it does not have a COM proxy stub registered.

To detect this condition, this probe makes the CLR do some extra work after an applicable QueryInterface call fails.  If the failure happens in a different context than the COM object's original context, the CLR will transition to the original context and try another QueryInterface call.  If this also fails, the CLR does nothing more; the original failure must have been unrelated to the context.  But if it succeeds, then that indicates that the QueryInterface failure is context-specific, so it emits the warning.

There's one other scenario in which this probe emits a warning: when a QueryInterface call fails in the object's original context, but the CLR has determined that this COM object is a standard proxy (because the interface pointer's address is in the range of the loaded ole32.dll).

What can you do about such failures?  You can register an appropriate type library or proxy-stub DLL, depending on the COM component. Or you can take steps to avoid context transitions, such as using the STAThreadAttribute.

Comments

  • Anonymous
    September 14, 2003
    The comment has been removed
  • Anonymous
    October 01, 2003
    Hi AdamI have this problem that I have been trying to solve for long but now I have almost given up. End to my knowledge it seems !The problem is this:I have developed a MMC Snap-in DLL in C# such that all the MMC COM-interfaces are redefined on .Net-side and given following attributes:
    [   ComImport, InterfaceType(ComInterfaceType.InterfaceIsIUnknown), Guid("955AB28A-5218-11D0-A985-00C04FD8D565")     ]
    The C# MMC snapin implements IComponent and IComponentData interfaces so that when MMC.exe executes, it can recognize this C# DLL as a COM-exposed Snap-in DLL and loads and displays it correctly in Snap-in console's left pane.IComponentData has an interface-method named Initialize() that is implemented by MySnap-in class and called by MMC at start-up. Inside Initialize(object pUnknown), I initialize an instance member (say, myObject) of the MySnap-in class with the object passed by MMC to the initialize(..) method during start-up. This object is saved as per MMC documentation so that it can be reused later-on to get IConsoleNamespace or any other MMC supported interfaces.And here is the problem. When I access this saved object myObject from anywhere within MMC-created-Thread (that is the thread that loads the snapin itself), it works fine . However, when I create a Timer(System.Threading.Timer or System.Timers.Timer) inside MySnapin class and I access myObject 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()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, still the Thread-method gives the same error when it accesses the myobject that was saved in Initialize() on MMC thread.So I am kind of despondent now. Any help would be really appreciated. Please write to me at nmkmurty@foxboro.com if you want any more clarifications regarind this problem.ThanksRaja
  • Anonymous
    April 11, 2004
    Yeah.
  • Anonymous
    April 11, 2004
    Free books for students, teachers, and the classic enthusiast.
  • Anonymous
    July 13, 2004
    I have been had this problem for a while... I am trying to find information about this but everybody has not solution...
    Please if anybody have an answer feedback me.

    Thanks.
    Israel
    ii_cuba@yahoo.com
  • Anonymous
    July 27, 2004
    The comment has been removed
  • Anonymous
    November 30, 2005
    Raja : Just have your timer thread create another thread that is STA to do this operation.