HighTechTalks DotNet Forums  

ComVisible true

Dotnet Framework (Interop) microsoft.public.dotnet.framework.interop


Discuss ComVisible true in the Dotnet Framework (Interop) forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
Steve
 
Posts: n/a

Default ComVisible true - 12-19-2005 , 04:38 PM






Hi,

We have a COM library with a .NET extensibility model which is achieved
using managed C++ (2.0) to aggregate managed classes. All is fine unless a
managed class exposes a custom managed interface in which case casting to the
interface from fails. The problem is solved by adding the ComVisible(true)
attribute. The doc says however that true is the default. Is using
aggregation a special case where this attribute must be explicity set or am i
mistaken on it's use.

From the doc:

The default is true, which indicates that the managed type is visible to
COM. This attribute is not needed to make public managed assemblies and types
visible; they are visible to COM by default.

Thanks,
Steve

Reply With Quote
  #2  
Old   
Jason Newell
 
Posts: n/a

Default Re: ComVisible true - 12-19-2005 , 04:48 PM






Steve,

There was an argument (discussion) about this a few weeks back. I
thought I'd try a little test and this is what I've found.

C#.NET 2003
- Create a new Class Library
- Set the "Register for COM Interop
- Build --> Sucess

C#.NET 2005 Express
- Create a new Class Library
- Set the "Register for COM Interop
- Build --> Fail (.dll does not contain any types that can be registered
for COM Interop)
- Decorate your class with [ComVisible(true)]
- Build --> Success

It would appear to me that in 2.0, it is not the default.

Jason Newell


Steve wrote:
Quote:
Hi,

We have a COM library with a .NET extensibility model which is achieved
using managed C++ (2.0) to aggregate managed classes. All is fine unless a
managed class exposes a custom managed interface in which case casting to the
interface from fails. The problem is solved by adding the ComVisible(true)
attribute. The doc says however that true is the default. Is using
aggregation a special case where this attribute must be explicity set or am i
mistaken on it's use.

From the doc:

The default is true, which indicates that the managed type is visible to
COM. This attribute is not needed to make public managed assemblies and types
visible; they are visible to COM by default.

Thanks,
Steve

Reply With Quote
  #3  
Old   
Willy Denoyette [MVP]
 
Posts: n/a

Default Re: ComVisible true - 12-19-2005 , 05:51 PM



Don't know about Express, but it's definitely not the case with VS Team
System.
But lets forget about VS versions and just try to build and register a class
from the command line (using Regasm.exe), you'll see that it works (it works
for me, and it should or it's a breaking issue). Can you try to register the
class that failed using regasm?

Willy.


"Jason Newell" <nospam (AT) nospam (DOT) com> wrote

Quote:
Steve,

There was an argument (discussion) about this a few weeks back. I thought
I'd try a little test and this is what I've found.

C#.NET 2003
- Create a new Class Library
- Set the "Register for COM Interop
- Build --> Sucess

C#.NET 2005 Express
- Create a new Class Library
- Set the "Register for COM Interop
- Build --> Fail (.dll does not contain any types that can be registered
for COM Interop)
- Decorate your class with [ComVisible(true)]
- Build --> Success

It would appear to me that in 2.0, it is not the default.

Jason Newell


Steve wrote:
Hi,

We have a COM library with a .NET extensibility model which is achieved
using managed C++ (2.0) to aggregate managed classes. All is fine unless
a managed class exposes a custom managed interface in which case casting
to the interface from fails. The problem is solved by adding the
ComVisible(true) attribute. The doc says however that true is the
default. Is using aggregation a special case where this attribute must be
explicity set or am i mistaken on it's use.

From the doc:

The default is true, which indicates that the managed type is visible to
COM. This attribute is not needed to make public managed assemblies and
types visible; they are visible to COM by default. Thanks,
Steve



Reply With Quote
  #4  
Old   
Jason Newell
 
Posts: n/a

Default Re: ComVisible true - 12-20-2005 , 07:25 AM



Willy,

Here are the results.

- Created a new C# 2005 Express Class Library Project.
- Register for COM Interop will be left off.

using System;

namespace COMTest
{
public class Class1
{
}
}

- Execute Build
- Execute regasm
--------------------------------------------------------------------------
C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727>rega sm
C:\Test\COMTest\COMTest\bin\Release\COMTest.dll
Microsoft (R) .NET Framework Assembly Registration Utility 2.0.50727.42
Copyright (C) Microsoft Corporation 1998-2004. All rights reserved.

RegAsm : warning RA0000 : No types were registered
--------------------------------------------------------------------------

- Change code like below.

using System;
using System.Runtime.InteropServices;

namespace COMTest
{
[ComVisible(true)]
public class Class1
{
}
}

- Execute Build
- Execute regasm
--------------------------------------------------------------------------
C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727>rega sm
C:\Test\COMTest\COMTest\bin\Release\COMTest.dll
Microsoft (R) .NET Framework Assembly Registration Utility 2.0.50727.42
Copyright (C) Microsoft Corporation 1998-2004. All rights reserved.

Types registered successfully
--------------------------------------------------------------------------

So Willy, am I doing something wrong here? I have 2 years experience
with COM Interop so I'm very familiar with how it works, in 1.1 anyway.
I'm just now starting to look at 2.0 hence my curiosity. Thanks.

Jason Newell


Willy Denoyette [MVP] wrote:
Quote:
Don't know about Express, but it's definitely not the case with VS Team
System.
But lets forget about VS versions and just try to build and register a class
from the command line (using Regasm.exe), you'll see that it works (it works
for me, and it should or it's a breaking issue). Can you try to register the
class that failed using regasm?

Willy.


"Jason Newell" <nospam (AT) nospam (DOT) com> wrote in message
news:e0YEk5OBGHA.312 (AT) TK2MSFTNGP09 (DOT) phx.gbl...

Steve,

There was an argument (discussion) about this a few weeks back. I thought
I'd try a little test and this is what I've found.

C#.NET 2003
- Create a new Class Library
- Set the "Register for COM Interop
- Build --> Sucess

C#.NET 2005 Express
- Create a new Class Library
- Set the "Register for COM Interop
- Build --> Fail (.dll does not contain any types that can be registered
for COM Interop)
- Decorate your class with [ComVisible(true)]
- Build --> Success

It would appear to me that in 2.0, it is not the default.

Jason Newell


Steve wrote:

Hi,

We have a COM library with a .NET extensibility model which is achieved
using managed C++ (2.0) to aggregate managed classes. All is fine unless
a managed class exposes a custom managed interface in which case casting
to the interface from fails. The problem is solved by adding the
ComVisible(true) attribute. The doc says however that true is the
default. Is using aggregation a special case where this attribute must be
explicity set or am i mistaken on it's use.

From the doc:

The default is true, which indicates that the managed type is visible to
COM. This attribute is not needed to make public managed assemblies and
types visible; they are visible to COM by default. Thanks,
Steve




Reply With Quote
  #5  
Old   
Jason Newell
 
Posts: n/a

Default Re: ComVisible true - 12-20-2005 , 07:52 AM



OK, I've figured out what's going on.

Assemblyinfo.cs has the following line by default from the template.

// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]


Jason Newell



Jason Newell wrote:
Quote:
Willy,

Here are the results.

- Created a new C# 2005 Express Class Library Project.
- Register for COM Interop will be left off.

using System;

namespace COMTest
{
public class Class1
{
}
}

- Execute Build
- Execute regasm
--------------------------------------------------------------------------
C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727>rega sm
C:\Test\COMTest\COMTest\bin\Release\COMTest.dll
Microsoft (R) .NET Framework Assembly Registration Utility 2.0.50727.42
Copyright (C) Microsoft Corporation 1998-2004. All rights reserved.

RegAsm : warning RA0000 : No types were registered
--------------------------------------------------------------------------

- Change code like below.

using System;
using System.Runtime.InteropServices;

namespace COMTest
{
[ComVisible(true)]
public class Class1
{
}
}

- Execute Build
- Execute regasm
--------------------------------------------------------------------------
C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727>rega sm
C:\Test\COMTest\COMTest\bin\Release\COMTest.dll
Microsoft (R) .NET Framework Assembly Registration Utility 2.0.50727.42
Copyright (C) Microsoft Corporation 1998-2004. All rights reserved.

Types registered successfully
--------------------------------------------------------------------------

So Willy, am I doing something wrong here? I have 2 years experience
with COM Interop so I'm very familiar with how it works, in 1.1 anyway.
I'm just now starting to look at 2.0 hence my curiosity. Thanks.

Jason Newell


Willy Denoyette [MVP] wrote:

Don't know about Express, but it's definitely not the case with VS
Team System.
But lets forget about VS versions and just try to build and register a
class from the command line (using Regasm.exe), you'll see that it
works (it works for me, and it should or it's a breaking issue). Can
you try to register the class that failed using regasm?

Willy.


"Jason Newell" <nospam (AT) nospam (DOT) com> wrote in message
news:e0YEk5OBGHA.312 (AT) TK2MSFTNGP09 (DOT) phx.gbl...

Steve,

There was an argument (discussion) about this a few weeks back. I
thought I'd try a little test and this is what I've found.

C#.NET 2003
- Create a new Class Library
- Set the "Register for COM Interop
- Build --> Sucess

C#.NET 2005 Express
- Create a new Class Library
- Set the "Register for COM Interop
- Build --> Fail (.dll does not contain any types that can be
registered for COM Interop)
- Decorate your class with [ComVisible(true)]
- Build --> Success

It would appear to me that in 2.0, it is not the default.

Jason Newell


Steve wrote:

Hi,

We have a COM library with a .NET extensibility model which is
achieved using managed C++ (2.0) to aggregate managed classes. All
is fine unless a managed class exposes a custom managed interface in
which case casting to the interface from fails. The problem is
solved by adding the ComVisible(true) attribute. The doc says
however that true is the default. Is using aggregation a special
case where this attribute must be explicity set or am i mistaken on
it's use.

From the doc:

The default is true, which indicates that the managed type is
visible to COM. This attribute is not needed to make public managed
assemblies and types visible; they are visible to COM by default.
Thanks,
Steve





Reply With Quote
  #6  
Old   
Willy Denoyette [MVP]
 
Posts: n/a

Default Re: ComVisible true - 12-20-2005 , 10:03 AM



That explains it all, I didn't pay attention to the assemblyinfo.cs as I'm
using my own assemblyinfo.cs template file in my projects.
The VS team decided to overrule the default at the assembly level, so now
you have to apply the attribute to each individual class your want to make
visible.


Willy.



"Jason Newell" <nospam (AT) nospam (DOT) com> wrote

Quote:
OK, I've figured out what's going on.

Assemblyinfo.cs has the following line by default from the template.

// Setting ComVisible to false makes the types in this assembly not
visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]


Jason Newell



Jason Newell wrote:
Willy,

Here are the results.

- Created a new C# 2005 Express Class Library Project.
- Register for COM Interop will be left off.

using System;

namespace COMTest
{
public class Class1
{
}
}

- Execute Build
- Execute regasm
--------------------------------------------------------------------------
C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727>rega sm
C:\Test\COMTest\COMTest\bin\Release\COMTest.dll
Microsoft (R) .NET Framework Assembly Registration Utility 2.0.50727.42
Copyright (C) Microsoft Corporation 1998-2004. All rights reserved.

RegAsm : warning RA0000 : No types were registered
--------------------------------------------------------------------------

- Change code like below.

using System;
using System.Runtime.InteropServices;

namespace COMTest
{
[ComVisible(true)]
public class Class1
{
}
}

- Execute Build
- Execute regasm
--------------------------------------------------------------------------
C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727>rega sm
C:\Test\COMTest\COMTest\bin\Release\COMTest.dll
Microsoft (R) .NET Framework Assembly Registration Utility 2.0.50727.42
Copyright (C) Microsoft Corporation 1998-2004. All rights reserved.

Types registered successfully
--------------------------------------------------------------------------

So Willy, am I doing something wrong here? I have 2 years experience
with COM Interop so I'm very familiar with how it works, in 1.1 anyway.
I'm just now starting to look at 2.0 hence my curiosity. Thanks.

Jason Newell


Willy Denoyette [MVP] wrote:

Don't know about Express, but it's definitely not the case with VS Team
System.
But lets forget about VS versions and just try to build and register a
class from the command line (using Regasm.exe), you'll see that it works
(it works for me, and it should or it's a breaking issue). Can you try
to register the class that failed using regasm?

Willy.


"Jason Newell" <nospam (AT) nospam (DOT) com> wrote in message
news:e0YEk5OBGHA.312 (AT) TK2MSFTNGP09 (DOT) phx.gbl...

Steve,

There was an argument (discussion) about this a few weeks back. I
thought I'd try a little test and this is what I've found.

C#.NET 2003
- Create a new Class Library
- Set the "Register for COM Interop
- Build --> Sucess

C#.NET 2005 Express
- Create a new Class Library
- Set the "Register for COM Interop
- Build --> Fail (.dll does not contain any types that can be
registered for COM Interop)
- Decorate your class with [ComVisible(true)]
- Build --> Success

It would appear to me that in 2.0, it is not the default.

Jason Newell


Steve wrote:

Hi,

We have a COM library with a .NET extensibility model which is
achieved using managed C++ (2.0) to aggregate managed classes. All is
fine unless a managed class exposes a custom managed interface in
which case casting to the interface from fails. The problem is solved
by adding the ComVisible(true) attribute. The doc says however that
true is the default. Is using aggregation a special case where this
attribute must be explicity set or am i mistaken on it's use.

From the doc:

The default is true, which indicates that the managed type is visible
to COM. This attribute is not needed to make public managed assemblies
and types visible; they are visible to COM by default. Thanks,
Steve







Reply With Quote
  #7  
Old   
Steve
 
Posts: n/a

Default Re: ComVisible true - 12-20-2005 , 04:14 PM



Thanks for find this guys. That does explain it all.

Steve

"Willy Denoyette [MVP]" wrote:

Quote:
That explains it all, I didn't pay attention to the assemblyinfo.cs as I'm
using my own assemblyinfo.cs template file in my projects.
The VS team decided to overrule the default at the assembly level, so now
you have to apply the attribute to each individual class your want to make
visible.


Willy.



"Jason Newell" <nospam (AT) nospam (DOT) com> wrote in message
news:uj0cxyWBGHA.1864 (AT) TK2MSFTNGP12 (DOT) phx.gbl...
OK, I've figured out what's going on.

Assemblyinfo.cs has the following line by default from the template.

// Setting ComVisible to false makes the types in this assembly not
visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]


Jason Newell



Jason Newell wrote:
Willy,

Here are the results.

- Created a new C# 2005 Express Class Library Project.
- Register for COM Interop will be left off.

using System;

namespace COMTest
{
public class Class1
{
}
}

- Execute Build
- Execute regasm
--------------------------------------------------------------------------
C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727>rega sm
C:\Test\COMTest\COMTest\bin\Release\COMTest.dll
Microsoft (R) .NET Framework Assembly Registration Utility 2.0.50727.42
Copyright (C) Microsoft Corporation 1998-2004. All rights reserved.

RegAsm : warning RA0000 : No types were registered
--------------------------------------------------------------------------

- Change code like below.

using System;
using System.Runtime.InteropServices;

namespace COMTest
{
[ComVisible(true)]
public class Class1
{
}
}

- Execute Build
- Execute regasm
--------------------------------------------------------------------------
C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727>rega sm
C:\Test\COMTest\COMTest\bin\Release\COMTest.dll
Microsoft (R) .NET Framework Assembly Registration Utility 2.0.50727.42
Copyright (C) Microsoft Corporation 1998-2004. All rights reserved.

Types registered successfully
--------------------------------------------------------------------------

So Willy, am I doing something wrong here? I have 2 years experience
with COM Interop so I'm very familiar with how it works, in 1.1 anyway.
I'm just now starting to look at 2.0 hence my curiosity. Thanks.

Jason Newell


Willy Denoyette [MVP] wrote:

Don't know about Express, but it's definitely not the case with VS Team
System.
But lets forget about VS versions and just try to build and register a
class from the command line (using Regasm.exe), you'll see that it works
(it works for me, and it should or it's a breaking issue). Can you try
to register the class that failed using regasm?

Willy.


"Jason Newell" <nospam (AT) nospam (DOT) com> wrote in message
news:e0YEk5OBGHA.312 (AT) TK2MSFTNGP09 (DOT) phx.gbl...

Steve,

There was an argument (discussion) about this a few weeks back. I
thought I'd try a little test and this is what I've found.

C#.NET 2003
- Create a new Class Library
- Set the "Register for COM Interop
- Build --> Sucess

C#.NET 2005 Express
- Create a new Class Library
- Set the "Register for COM Interop
- Build --> Fail (.dll does not contain any types that can be
registered for COM Interop)
- Decorate your class with [ComVisible(true)]
- Build --> Success

It would appear to me that in 2.0, it is not the default.

Jason Newell


Steve wrote:

Hi,

We have a COM library with a .NET extensibility model which is
achieved using managed C++ (2.0) to aggregate managed classes. All is
fine unless a managed class exposes a custom managed interface in
which case casting to the interface from fails. The problem is solved
by adding the ComVisible(true) attribute. The doc says however that
true is the default. Is using aggregation a special case where this
attribute must be explicity set or am i mistaken on it's use.

From the doc:

The default is true, which indicates that the managed type is visible
to COM. This attribute is not needed to make public managed assemblies
and types visible; they are visible to COM by default. Thanks,
Steve








Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.