Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / Interop / December 2004

Tip: Looking for answers? Try searching our database.

Can't communicate with COM server, QueryInterface Failed

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
DGreen13 - 07 Dec 2004 16:41 GMT
I have a c# program that instantiates a C++ COM server program.

I then try to call a method on the server object and get the following:

An unhandled exception of type 'System.InvalidCastException' occurred in
mscorlib.dll

Additional information: QueryInterface for interface NestOle.INstOle failed.

I created the interop in the VS2003 IDE . The methods appear through
intellisense as I type, they just don't run.

I was given another client program written in C++ that connects to the same
COM Server and it works fine.

Interop is new to me and after a few days of trying everything I could find
on the net I'm still stuck.

Any suggestions would be most appreciated

Thankyou
"Peter Huang" [MSFT] - 08 Dec 2004 08:45 GMT
Hi

It may be caused by the fact that we did not register all the necessary
typelibrary.
You may try to register the typelibrary of the COM EXE with the regtlib.exe
tool.
Usually we can find it in the path below.

Microsoft Visual Studio .NET (2003) Enterprise Architect  40,960  3/16/2001
oainst.cab  \msdn\ie60  
Microsoft Visual Studio .NET (2003) Enterprise Architect  40,960  3/16/2001
oainst.cab  \wcu\ie60sp1  

Best regards,

Perter Huang
Microsoft Online Partner Support

Signature

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.

DGreen13 - 08 Dec 2004 10:39 GMT
Hi Peter

I ren regtlib on the tlb file and it reported success but now I can't add a
reference to the tlb in my project.

I ran tlbimp on the tlb and I can import the dll it created but I still get
the same QueryInterface failed problem

Thanks

Dave

> Hi
>
[quoted text clipped - 16 lines]
> Get Secure! - www.microsoft.com/security
> This posting is provided "AS IS" with no warranties, and confers no rights.
"Peter Huang" [MSFT] - 09 Dec 2004 03:15 GMT
Hi

Did your COM component depend on other COM component?
If so, I think you may also need to regtlib of those ones.
Or can you reproduce the problem with a simple Test COM Component?
If yes, I think we may need to try on another machine.
If no, I think we can add the interface and method one by one to
troubleshooting what cause the problem.

Hope this helps.

Best regards,

Perter Huang
Microsoft Online Partner Support

Signature

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.

DGreen13 - 09 Dec 2004 08:55 GMT
I think you are right but I don't have a separate tlb file for any other
components. I searched the registry and removed all references to my COM
Object, ran the object from its exe and that set up the registy entries on
its own. That then allowed me to add the reference.

What I did find was an entry in the registry for an item that wasn't
showing up anywhere else in the interop dll.

I was then able to invoke as follows:

Type m_nest = Type.GetTypeFromProgID ("NestOle.Document");
                               
            object ibaseObject = Activator.CreateInstance(m_nest);

            object[] arguments = new object [] {"c:\\nestmgr\\batch\\13.bat"};

            m_nest.InvokeMember ("goNest",BindingFlags.Default |
BindingFlags.InvokeMethod,null,ibaseObject,arguments);

This works, but is not quite as tidy as other COM componenets that just
needed adding as a reference, instantiating with "new" and calling their
methods. I can obviously now write my own wrapper class based on this to
simplify the method calls.

Does this mean the COM/tlb are not written "correctly" and so VS is missing
this component when creating the interop dll or have I missed something.

Thankyou for your help Peter

> Hi
>
[quoted text clipped - 14 lines]
> Get Secure! - www.microsoft.com/security
> This posting is provided "AS IS" with no warranties, and confers no rights.
"Peter Huang" [MSFT] - 10 Dec 2004 03:35 GMT
Hi

Do you mean the late-binding via the InvokeMember will work, but if you use
the early-binding then the com server will not work?
If so, I think you are right, it seems that the Interop Assembly generated
by IDE may not be correct.

So far, I think you workaround is correct, that is to write the Wrap
yourself.

Hope his helps.

Best regards,

Perter Huang
Microsoft Online Partner Support

Signature

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.

DGreen13 - 10 Dec 2004 08:39 GMT
Yes the late binding works, but the early binding doesn't.

I'm happy with my workaround and I've learnt a lot about interop in the mean
time.

Thank you very much for your help, I can now get on with the rest of my
project

Dave

> Hi
>
[quoted text clipped - 15 lines]
> Get Secure! - www.microsoft.com/security
> This posting is provided "AS IS" with no warranties, and confers no rights.
"Peter Huang" [MSFT] - 13 Dec 2004 05:28 GMT
Hi

Thanks for your quickly reply!

I am glad my suggestion helped you.

Best regards,

Perter Huang
Microsoft Online Partner Support

Signature

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.

DGreen13 - 08 Dec 2004 10:39 GMT
Hi Peter

I tried running "regtlib nestole.tlb" and it reported success, however now I
can't import the nestole.tlb as a reference in my project. I get the error "A
reference to 'nestole.tlb' could not be added. Could not load the type
library. Eror loading type library/DLL".

I tried running tlbimp.exe on the file and I can add the new dll as a
reference, but when I run the program I still get the same error.

Thanks

> Hi
>
[quoted text clipped - 16 lines]
> Get Secure! - www.microsoft.com/security
> This posting is provided "AS IS" with no warranties, and confers no rights.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.