Looks like the declared type of property OPCHDAItems
is not IOPCHDAItems
- it's OPCHDAServerClass
. C# is a statically typed language - it won't typecast COM interfaces unless explicitly told to, and it won't go for the IDispatch unless told to. Rephrase like this:
server.Connect("MyServerName");
OPCHDAItem item = (server.OPCHDAItems as IOPCHDAItems).AddItem("MyItem",1);
EDIT: try this first:
IOPCHDAItems Items = server.OPCHDAItems;
Still the same error? How about
IOPCHDAItems Items = server.OPCHDAItems as IOPCHDAItems;