By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,893 Members | 1,721 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,893 IT Pros & Developers. It's quick & easy.

Unable to cast COM object of type 'System.__ComObject' to class type 'System.String

P: 3

Please help, this has been driving me nuts for nearly 2 days now.

This vb6 code works:

Public oEng As New ebizEngine
Public oMsg As ebizMessage

Function EbizGetFromQueue() As String
Set oMsg = oEng.RecvMessage
If oMsg Is Nothing Then
' the end
EbizGetFromQueue = "*END"
EbizGetFromQueue = oMsg.Body
End If

In c# I have this:

private eBiz2000.ebizEngineClass ebizEngine = new eBiz2000.ebizEngineClass();

public string getFromQueue()
eBiz2000.ebizMessage ebizMessage;
ebizMessage = ebizEngine.RecvMessage();
if (ebizMessage == null) // not sure about this??
return "*END";

return (string)ebizMessage.Body;

When this runs I get the error Unable to cast COM object of type 'System.__ComObject' to class type 'System.String'. Instances of types that represent COM components cannot be cast to types that do not represent COM components; however they can be cast to interfaces as long as the underlying COM component supports QueryInterface calls for the IID of the interface.
I've tried numerous things with no success, any help is greatly appreciated.
Mar 26 '08 #1
Share this Question
Share on Google+
2 Replies

Expert 5K+
P: 7,872
ebizMessage.Body is not a string type.
Mar 26 '08 #2

P: 3
ebizMessage.Body is not a string type.
It is an object, how can I get to the string it contains? How does the vb work but not the c#?
Mar 26 '08 #3

Post your reply

Sign in to post your reply or Sign up for a free account.