From: Tony Johansson on
Hi!

I have this class library that is called from COM.
The strange thing is that even if I add this attribute [ComVisible(false)]
to the only method that the COM can call it still work.
Accordingly to the docs this attibute will hide those members that have this
attribute set to false like this [ComVisible(false)]

So why won't this work in my case ?

using System;
using System.Runtime.InteropServices;
using System.Windows.Forms;

namespace MyInterop
{
/// <summary>
/// Summary description for Class1.
/// </summary>
///

[Guid("3E0E2EB2-CC13-40fb-9346-34809CB2418C")]
public interface IMyDotNetInterface
{
void ShowDialog();
}


[ClassInterface(ClassInterfaceType.None)]
[Guid("3A13EB34-3930-4e06-A3EB-10724CCC2F4B")]
public class MyDotNetClass:IMyDotNetInterface
{
public MyDotNetClass()
{}

[ComVisible(false)]
public void ShowDialog()
{
MessageBox.Show ("I am a Managed DotNET C# COM Object Dialog");
}
}
}

//Tony


From: Tony Johansson on

"Tony Johansson" <johansson.andersson(a)telia.com> skrev i meddelandet
news:extQqFu5KHA.6052(a)TK2MSFTNGP02.phx.gbl...
> Hi!
>
> I have this class library that is called from COM.
> The strange thing is that even if I add this attribute [ComVisible(false)]
> to the only method that the COM can call it still work.
> Accordingly to the docs this attibute will hide those members that have
> this attribute set to false like this [ComVisible(false)]
>
> So why won't this work in my case ?
>
> using System;
> using System.Runtime.InteropServices;
> using System.Windows.Forms;
>
> namespace MyInterop
> {
> /// <summary>
> /// Summary description for Class1.
> /// </summary>
> ///
>
> [Guid("3E0E2EB2-CC13-40fb-9346-34809CB2418C")]
> public interface IMyDotNetInterface
> {
> void ShowDialog();
> }
>
>
> [ClassInterface(ClassInterfaceType.None)]
> [Guid("3A13EB34-3930-4e06-A3EB-10724CCC2F4B")]
> public class MyDotNetClass:IMyDotNetInterface
> {
> public MyDotNetClass()
> {}
>
> [ComVisible(false)]
> public void ShowDialog()
> {
> MessageBox.Show ("I am a Managed DotNET C# COM Object Dialog");
> }
> }
> }
>
> //Tony

This ComVisibleAttributeattribute is a Design-Time Attributes and here is
what the docs says about it
This attribute specifies whether this member is exposed to COM. It accepts
true or false; the default value is true. Setting the attribute to false on
the assembly hides all public types within the assembly. You can selectively
make types visible within the assembly by setting the individual types to
true.

Setting the attribute to false on a specific type hides that type and its
members. However, you cannot make members of a type visible if the type is
invisible. Setting the attribute to false on a type prevents that type from
being exported to a type library.

So if I set this ComVisibleAttribute to false as I have done this should
result in that my method ShowDialog should not be visible for COM but this
attribute settings has no effect my method is still visible for COM.

//Tony



From: Peter Duniho on
Tony Johansson wrote:
> [...]
> So if I set this ComVisibleAttribute to false as I have done this should
> result in that my method ShowDialog should not be visible for COM but this
> attribute settings has no effect my method is still visible for COM.

Without a concise-but-complete code example, it's hard to say for sure.
But, is it possible that you have forgotten to unregister the type
from the previous COM-visible build, causing the new type library to
have no effect?

Alternatively, you can always look at the type library directly and see
if the attribute is doing what is says it's supposed to do. That will
at least let you know where to look for the problem.

Pete
From: Tony Johansson on
"Peter Duniho" <no.peted.spam(a)no.nwlink.spam.com> skrev i meddelandet
news:ewTJER25KHA.1888(a)TK2MSFTNGP05.phx.gbl...
> Tony Johansson wrote:
>> [...]
>> So if I set this ComVisibleAttribute to false as I have done this should
>> result in that my method ShowDialog should not be visible for COM but
>> this
>> attribute settings has no effect my method is still visible for COM.
>
> Without a concise-but-complete code example, it's hard to say for sure.
> But, is it possible that you have forgotten to unregister the type from
> the previous COM-visible build, causing the new type library to have no
> effect?
>
> Alternatively, you can always look at the type library directly and see if
> the attribute is doing what is says it's supposed to do. That will at
> least let you know where to look for the problem.
>
> Pete

My communication is from COM to managed code so the type library is a COM
thingy that describe the COM so I can't use neither ILDASM or Red Gats's
Reflector to eximine this type library

If the communication had been from managed code to COM I would have been
able to look into this type library by using either ildasm ot Red Gats's
Reflector.

So what do you mean by saying Alternatively, you can always look at the type
library directly and see
if the attribute is doing what is says it's supposed to do. That will at
least let you know where to look for the problem.

So here is the component I have one .NET library dll one COM exe file one
type library that describe the COM component.
What steps exactly should I use to make this work when I use this ComVisible
attribute.

//Tony


From: Tony Johansson on
"Peter Duniho" <no.peted.spam(a)no.nwlink.spam.com> skrev i meddelandet
news:ewTJER25KHA.1888(a)TK2MSFTNGP05.phx.gbl...
> Tony Johansson wrote:
>> [...]
>> So if I set this ComVisibleAttribute to false as I have done this should
>> result in that my method ShowDialog should not be visible for COM but
>> this
>> attribute settings has no effect my method is still visible for COM.
>
> Without a concise-but-complete code example, it's hard to say for sure.
> But, is it possible that you have forgotten to unregister the type from
> the previous COM-visible build, causing the new type library to have no
> effect?
>
> Alternatively, you can always look at the type library directly and see if
> the attribute is doing what is says it's supposed to do. That will at
> least let you know where to look for the problem.
>
> Pete

Hi!

To make sure that I run a new version of the .NET library dll I changed
something in the text that the MessageBox is writing
and that works. So I do know that I succeed to make the COM to use my new
dll version.
But the same problem exist that the ComVisible(false) doesn't work. It could
be a bug.

[System.Runtime.InteropServices.ComVisible(false)]
public void ShowDialog()
{
MessageBox.Show ("I. am a Managed DotNET C# COM Object Dialog..");
}

//Tony