Click here to Skip to main content
15,885,942 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a COM Class which is registered in to ROT, through an other application i am fetching the instance of my com class from ROT and casting it to its type giving following error.

Unable to cast COM object of type 'System.__ComObject' to interface type 'ROTViewer.IHandleVIParentInfo'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{C4B3F18E-FDF1-3F0C-A6DB-F03B302CAE9F}' failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)).


Following is my COM class implementation
C#
 public interface IHandleVIParentInfo
{
    Dictionary<int, string> ContainerParentredVi {get; set;}
    int GetListCount();
}

[ComVisible(true)]
[ClassInterface(ClassInterfaceType.None)]
[ComSourceInterfaces(typeof(IHandleVIParentInfo))]
[ProgIdAttribute(&quot;Qcs.VIParentedInfoHandler&quot;)]
[GuidAttribute(HandleVIParentedInfo.Guid)]
[DisplayName(&quot;Qcs VI Parented Info Handler&quot;)]
public class HandleVIParentedInfo : IDisposable, IHandleVIParentInfo
{
    public const string Guid = &quot;CB6BFC97-F8E3-4fce-B68B-4D01485811A1&quot;;
    public Dictionary&lt;int, string&gt; ContainerParentredVi
    {
        get
        {
            return _containerParentredVi;
        }
        set
        {
            _containerParentredVi = value;
        }
    }
    private Dictionary&lt;int, string&gt; _containerParentredVi = new Dictionary&lt;int, string&gt;();
    public HandleVIParentedInfo()
    {
        //private Dictionary&lt;int, string&gt; _containerParentredVi = new Dictionary&lt;int, string&gt;();
    }

    #region IDisposable Members

    void IDisposable.Dispose()
    {
        throw new NotImplementedException();
    }

    #endregion

    #region IHandleVIParentInfo Members

    int IHandleVIParentInfo.GetListCount()
    {
        return ContainerParentredVi.Count;
    }

    #endregion
}</pre>


Following is method where i am type casting an object to my com class type

C#
        public static void GetIDEInstances()
        {
            instances = new List<object>();
            Hashtable runningStationInstances = new Hashtable();
            Hashtable runningObjects = GetROTContent();
           
            
            object expectedObj;
            //runningObjects["!{5EB461D8-71CD-4E78-A360-4CE788A93063}"].GetHashCode();
            IDictionaryEnumerator rotEnumerator = runningObjects.GetEnumerator();
            while (rotEnumerator.MoveNext())
            {
                string candidateName = (string)rotEnumerator.Key;
                if (string.Compare(candidateName,"!{CB6BFC97-F8E3-4fce-B68B-4D01485811A1}",true)==0)
                {
                    
                    viParenting = (IHandleVIParentInfo)rotEnumerator.Value;
                    
                   
                }
            }
}


getting error in the line "viParenting = (IHandleVIParentInfo)rotEnumerator.Value;"
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900