![]() | |
![]() |
| | Thread Tools | Search this Thread | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
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 |
#3
| |||
| |||
|
|
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 |
#4
| |||
| |||
|
|
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 |
#5
| |||
| |||
|
|
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 |
#6
| |||
| |||
|
|
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 |
#7
| |||
| |||
|
|
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 |
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
| |