Referencing a .NET assembly for COM interop

Banana

Member
Joined
Aug 7, 2008
Messages
6
Programming Experience
Beginner
Using VB.NET VS 2005.

I have a .NET library that I need to be accessible for COM clients. I originally written a extra class within the library's source code (which was C#) and simply ticked the checkbox to register it for COM Interop. It works, but with late binding only.

Now, I want to implement early binding, and didn't want to expose all classes within the library, so I decided to write a separate assembly to act as a wrapper in VB.NET. This compile successfully, but I notice there isn't a .TLB file generated, even though I've ticked "Make assembly COM-visible". I used regasm to register the .TLB.

However, when the COM client try to use it, it will get an error saying "Automation Error: Cannot find the specified file."

I suspect that even though the library is correctly referenced within .NET, it's not being exposed properly to the COM clients and thus all they have is a wrapper that points to nothing. Mind you, the early binding works perfectly. It just won't run.

Any suggestions on how I can further diagnose and fix this problem?
 
Update.

After rewriting the wrapper in a C# library, it works smoothly.

Apparently, "Make Assembly COM-visible" isn't VB.NET's equivalent to C#'s "Register for COM Interop", as C# has the same "Make Assembly COM-Visible" and from what I understand, both needs to be ticked for automagic registration.

The problem?

According to MSDN, I only need to go to Compile tab of project properties and check the box "Register for COM Interop". Except that there is none to be found at all. I've looked all over and consulted the help which tell me to do the same thing. I've installed SP1 in hope that it would fix it to no avail.

So where is this mythical "Register for COM Interop" that seems to be easily discoverable in C# but not in VB.NET?!?
 
Thanks so much for that information.

The headscratcher, however, is that there's nothing from Microsoft that explicitly states that Express will not have this feature enabled. (And why only VB.NET and not C# express?). This walkthrough you referred to, this was what I was referring to in my OP; it gives no indication that feature is not available in express.

As for commandline options, I didn't realize I had to either add to GAC (not sure what this is) or raise the flag /codebase. Will fiddle with it and see if results improve.

Thanks!
 
Banana said:
headscratcher
Express also doesn't contain a COM class template project, you just have to assume Express has limitations and doesn't have everything Pro edition has. Why C# Express? It is a tool for more details, as with C++ even more. Creating Com libraries in not a standard feature as such, .Net is a managed development environment, as opposed to unmanaged Com. Interacting with unmanaged code from a .Net perspective is an exception and requires special conversions and tools.

GAC is a central place assemblies can be registered to be available globally when used from different system locations, this is also an exception to how .Net libraries normally are used. The /codebase switch on the other hand registers the dll location specifically.
To Gac the signed assembly use the Gacutil.exe commandline tool like this to install/uninstall:
gacutil /i ComClassLib.dll
gacutil /u ComClassLib
 
Thank you, John for the help. Much obliged.

Just last thing I need to figure out.

As mentioned, the VB.NET project references a already built C# library. Since I have to use command line options, I need to strong name the project but I cannot do so with the C#. Is there a means to do this partially (just strong name the wrapper and leave the reference library alone)?

I can strong name within C# but want to know about the case where I only have the DLL file and no source code.

Thanks!


Edit: After some searching, it sounds like strong-naming is simply not going to permit referencing to other assembly that aren't strong named. However I am confused about the /codebase because some sites suggest that it can be used anyway without a strong name (as long the namespace is unique). If anyone can confirm whether this is in fact possible (and viable), I would be much obliged.
 
Last edited:
Since I have to use command line options, I need to strong name the project but I cannot do so with the C#.
There is no difference between you or VS registering it with Regasm, you have to sign it either way.
strong-naming is simply not going to permit referencing to other assembly that aren't strong named.
Correct, unsigned assemblies are inherently unsafe and it doesn't cost a dime to sign one, so much for whoever threw that one on you.
I am confused about the /codebase because some sites suggest that it can be used anyway without a strong name (as long the namespace is unique). If anyone can confirm
All you got to do is try, it would take you just a few seconds to try this yourself. Here's output, and library works afterwards.
RegAsm : warning RA0000 : Registering an unsigned assembly with /codebase can cause
your assembly to interfere with other applications that may be installed on
the same computer. The /codebase switch is intended to be used only with signed
assemblies. Please give your assembly a strong name and re-register it.
Types registered successfully
Assembly exported to '...\ComClassLib.tlb', and the type library was registered successfully
So if you are comfortable with possibly causing problems with both your own and some other application in your own system just do it, but I wouldn't recommend a large scale deployment.
 
John-

You've been a big help.

I did in fact try it and it does seems to work. I just didn't feel that I was adequately understanding the ramifications of ignoring the warning, hence my question.

(BTW, how do I mark this thread as answered?)
 
Back
Top