COM interfaces issues: Please help!


G

Guest

Hi,

I have a class with some functions that I want to be available via COM
interop. I declared the interface, which the class is based on, like this:

[Guid("F2B5A004-9D1C-4fba-B8BE-D7C6B08618CD")]
public interface IA
{
[DispId(1)]
string Test();

[DispId(2)]
bool SaveChanges();

[DispId(3)]
bool SendResults();
}

Now, I want my class to also implement a second interface which is located
in another assembly (another C# project to which I made a reference in my
current project) that has the following definition:

public interface IB
{
bool UpdateInformation();
}

I don't want any functions or properties from IB to be exported or available
through COM interop. Basically, I then defined my class like this:

[Guid("AAC98A5E-8AA5-49fb-B0D7-EE6E6902D1B8"),
ClassInterface(ClassInterfaceType.None)]
public class MyClass : IA, ExternalNamespace.IB
{ ... }

I made sure to implement every function from both interfaces. Now, when I
try to compile this solution without the "Register for COM interop" set to
true, everything is fine. But if I set the option to true, I get the
following error when compiling my current project (the one with the class
implementing the two interfaces):

COM Interop registration failed. Could not find a type library for assembly
'X'.

'X' is my external project referenced in the current project (it compiles to
a Class Library and does not have anything related to COM interop in it).

Why am I getting this error and how can I have a class inherit two
interfaces with only one enabled for COM interop.

Thanks a lot,

Skip.
 
Ad

Advertisements

J

John Puopolo

Skip:

I've not tried this, but perhaps you can use the ComVisible attribute to
specifically hide the IB interface from COM interop? It appears from a
quick look at the doc that you can apply ComVisible fairly granularly.

Anyone else have thoughts on this?

John
 
Ad

Advertisements

G

Guest

John,

Your solution seems to have solved my problem, thanks. Here's the
definition of my second interface if anyone ever reads this thread in the
future:

[ComVisible(false)]
public interface IB
{
bool UpdateInformation();
}


Skip.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top