Can't create Type Library File with Visual Studio 2010 generated DLL, but can with command-line compiled
If you create a new Class Library in Visual Studio, the default AssemblyInfo.cs file includes the line:
[assembly: ComVisible(false)]
The command-line command you're using is only compiling your TestClass.cs file, so you get the default setting for ComVisible (which, judging from the available evidence, is probably true
). When you compile from the IDE, you include AssemblyInfo.cs as well, so its explicit setting overrides the compiler's default.
Related videos on Youtube
Clinton Pierce
Professionally programming since I was 15 or so. Not a language bigot -- after a while, they all look the same. Published some Perl books back in the dot-com heyday. You may remember me from such conferences as YAPC, The Perl Conference (before they were OSCON!), and USENIX LISA. Any code posted to this site by me should be considered in the Public Domain unless otherwise noted.
Updated on June 04, 2022Comments
-
Clinton Pierce almost 2 years
I have a TestClass.cs file that contains an interface, and a class, much like this:
namespace CPierce.CSharpBridge { [System.Runtime.InteropServices.Guid("3D08DF02-EFBA-4A65-AD84-B08ADEADBEEF")] public interface ICSide { // interface definition omitted... } [System.Runtime.InteropServices.Guid("CBC04D81-398B-4B03-A3D1-C6D5DEADBEEF")] public partial class CSide : ICSide { // class definition omitted... } }
When I compile this at the command line, and run regasm on it:
csc /debug /t:library TestClass.cs regasm TestClass.dll /tlb:TestClass.tlb
I get a nice, big .tlb file suitable for including in a C++ project elsewhere....
10/27/2011 01:50 PM 3,616 TestClass.tlb
When I put TestClass.cs into a "Class Project" in Visual Studio, compile it, run regasm, the resulting .tlb is pathetic and nearly useless -- it has no interface, no method signatures, etc...
[Compiled TestClass.cs as part of Project "ClassProject" in Visual Studio] regasm ClassProject.dll /tlb:ClassProject.dll 10/27/2011 01:58 PM 1,132 ClassProject.tlb
This is the same C# code in both cases, one being compiled with Visual Studio one at the command line, giving me completely different results.
What gives?
--
Update: Hans suggests that the
[ComVisible(true)]
attribute missing is causing the problem. Tried it, and it worked. But that still doesn't answer the question, why? Why do I get different results based on which compile method I use?-
user1703401 over 12 yearsYou forgot the [ComVisible(true)] attribute.
-
user1703401 over 12 yearspossible duplicate of Exsposing indexer like properties to COM
-
Clinton Pierce over 12 yearsRight...but why does that only affect the Visual Studio compilation and not the command-line version?
-
user1703401 over 12 years"Make assembly COM-Visible" option in the IDE, I guess.
-