COM interfaces issues: Please help!

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Skip

    COM interfaces issues: Please help!

    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 UpdateInformati on();
    }

    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( ClassInterfaceT ype.None)]
    public class MyClass : IA, ExternalNamespa ce.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.

  • John Puopolo

    #2
    Re: COM interfaces issues: Please help!

    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


    "Skip" <Skip@discussio ns.microsoft.co m> wrote in message
    news:AA0DBE66-A33C-4613-AC8E-41213E64F16D@mi crosoft.com...[color=blue]
    > 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[/color]
    this:[color=blue]
    >
    > [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 UpdateInformati on();
    > }
    >
    > I don't want any functions or properties from IB to be exported or[/color]
    available[color=blue]
    > through COM interop. Basically, I then defined my class like this:
    >
    > [Guid("AAC98A5E-8AA5-49fb-B0D7-EE6E6902D1B8"),
    > ClassInterface( ClassInterfaceT ype.None)]
    > public class MyClass : IA, ExternalNamespa ce.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[/color]
    assembly[color=blue]
    > 'X'.
    >
    > 'X' is my external project referenced in the current project (it compiles[/color]
    to[color=blue]
    > 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.
    >[/color]


    Comment

    • Skip

      #3
      Re: COM interfaces issues: Please help!

      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(fals e)]
      public interface IB
      {
      bool UpdateInformati on();
      }


      Skip.

      "John Puopolo" wrote:
      [color=blue]
      > 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
      >
      >[/color]

      Comment

      Working...