regasm.exe

Registration Assembly Tool
To register or unregister a .NET component you must run a command-line tool called the Registration Assembly Tool (Regasm.exe).
Regasm.exe adds information about the class to the registry to allow COM clients to access the .NET classes.
The RegistrationServices class provides the equivalent API functionality.
Once the class has been registered a COM client can use it as a COM component.
Class registration and type library registration.


File Location

.NET Framework 2.0, 3.0, and 3.5 use the same RegAsm.exe which is located in the .NET Framework V2.0 folder.

C:\WINNT\Microsoft.NET\Framework\v2.0.50727\RegAsm.exe 
C:\Windows\Microsoft.NET\Framework\v2.0.50727\RegAsm.exe

.NET Framework 4.0 uses a new RegAsm.exe which is located in the .NET Framework V4.0 folder.

C:\WINNT\Microsoft.NET\Framework64\v4.0.30319\RegAsm.exe 
C:\Windows\Microsoft.NET\Framework64\v4.0.30319\RegAsm.exe

Command Line Parameters

/tlb parameter - You can use this parameter to generate (and register) a corresponding tlb file for the given assembly
Regasm.exe places the generated type libraries in the current working directory or the directory specified for the output file.

regasm myBetterFile.dll /tlb:myTest.tlb 

/codebase - You need to use this if you want your dll registered locally and not being installed into the GAC.

regasm myBetterFile.dll /codebase 

Register for COM Interop

On the Project Properties, Build tab, there is a checkbox called "Register for COM Interop"
This provides a way of automatically running the RegAsm utility after the build has completed.
This will create a .tlb file in the bin folder and will register the dll on your machine.
The exact regasm command that runs will vary depending on which platform you are targetting and also what .NET Framework you are using.
There was a known bug (KB956933) in earlier versions of Visual Studio because this option always used the 32 bit version of the RegAsm.
Instead of using the "Register for COM Interop" checkbox you could alternatively add a post-build event.

%SystemRoot%\Microsoft.NET\Framework64\v4.0.30319\RegAsm.exe "$(TargetPath)" /tlb: "$(TargetDir)$(TargetName).tlb" /codebase 

Callable Wrapper

When a COM Client calls a .NET object, the common language runtime creates the managed object an a COM Callable Wrapper (CCW) for the object.
COM Clients cannot reference a .NET component directly but instead use the COM Callable Wrapper as a proxy for the managed object.
The CCW needs to marshall the COM types.
The CCW is basically a type library (.tlb)
The manifest information in the .NET assembly needs to be converted into IDL.
When a COM Add-in is installed on a user's system, registry entries are created for the Add-in.
The Regsvr32 utility will not work for .NET components.


Regsvr32

This will load the library and try and call DLLRegisterServer
This cannot generate a tlb file
more information


© 2019 Better Solutions Limited. All Rights Reserved. © 2019 Better Solutions Limited TopPrevNext