Custom Search

How to register a C# or VB.Net DLL

After you created a C# or VB.Net DLL, you need to register it on a target machine. You can use Microsoft's RegAsm.exe utility.

Regasm.exe is an Assembly Registration tool used to read the metadata within an assembly. It also adds the necessary entries to the registry allowing a COM client (VB6 applications, or Microsoft VBA, eg. Access, Excel, etc) to create .NET Framework classes. Once a class is registered using Regasm.exe, a COM client can use it as a COM component.

RegAsm.exe file comes with .Net framework installation and can be found in Microsoft.NET framework folder. There are different versions of RegAsm.exe.

  1. .Net framework 2.0, 3.0, and 3.5 use the same RegAsm.exe which locates in the .Net framework V2.0 folder.




  2. .Net framework 4.0 uses a new RegAsm.exe which locates in the .Net framework V4.0 folder.




RegAsm.exe and DLL mapping

If you receive this error "RegAsm : error RA0000 : Failed to load 'c:\winnt\system32\YourDLLFile.dll' because it is not a valid .NET assembly", you are probably trying to use a .Net framework 2 RegAsm.exe to register a DLL that is created by using .Net framework 4.

.Net Framework RegAsm.exe default installation path Your DLL should be created by
.Net framework 2.0/3.0/3.5 C:\WINNT\Microsoft.NET\Framework\v2.0.50727\RegAsm.exe .Net framework 2.0/3.0/3.5
.Net framework 4.0 C:\WINNT\Microsoft.NET\Framework\v4.0.30319\RegAsm.exe .Net framework 4.0

So when registering DLL assemblies that are created by .Net framework 4, we must NOT use RegAsm.exe that comes in .Net framework 2.0/3.0/3.5 folder.

How to run RegAsm.exe

To execute RegAsm.exe, open a command prompt window, and navigate to the folder where RegAsm.exe is located and run it (otherwise you will get "RegAsm is not recognized as internal or external command, operable program or batch file" error message).

Assume I have already added my DLL to folder C:\WINNT\system32 then I can run the following command:

C:\WINNT\Microsoft.NET\Framework\v4.0.30319\RegAsm.exe SimpleCalc.dll /codebase

Note that you don't need to specify C:\WINNT\system32 in the command as it's a system folder. RegAsm.exe will automatically look up SimpleCalc.dll in C:\WINNT\system32 directory.

The /codebase parameter is an optional parameter that adds information about the DLL to the Windows registry which specifies the assembly's path on the disk.

Regasm can also be used to unregister a DLL.

If the DLL you got does not have type library file associated with it, one can be generated by using the Regasm utility and the /tlb option.

C:\WINNT\Microsoft.NET\Framework\v4.0.30319\RegAsm.exe SimpleCalc.dll /tlb:SimpleCalc.tlb

Note that, to export a type library from the DLL, you need administrator privileges on the computer, or you will receive this type of error "RegAsm : error RA0000 : An error occurred while saving the exported type library: Access is denied..." because the account under which you run regasm.exe doesn't have rights to write to the folder.

Note that you can create environmental variables for the .Net framework RegAsm.exe to simplify DLL registration.

Happy Registering!


Related Articles:

1.Create a DLL by CSharp or VB.Net for VBA
2.How to correctly reference and call a DLL

Other Recent Articles from the MS Access category:

1.Solved - the size of the Access query result is larger than the maximum size of a database (2 GB)
2.How to easily get a list of field names in MS Access
3.How to count distinct records in MS Access
4.How to do transaction based processing in MS Access
5.How to open a document (local/network file or web page) from MS Access
6.How to use ADOX to create unique composite index - the VBA approach
7.How to do cross-table update queries in MS Access - the right way
8.Three efficient ways to get the number of records by using VBA
9.How to create a composite unique index (not as a primary key) in MS Access
10.Use VBA to get the correct number of records in a Recordset object
11.Disable Access Prompt when a record is changed, table deleted, or action queries run
12.How to hide and unhide a MS Access object
13.How to return multiple values from a VBA function (Part 3)
14.How to return multiple values from a VBA function (Part 2)
15.How to return multiple values from a VBA function (Part 1)
16.Three ways to programmatically duplicate a table in MS Access by VBA
17.Create a DLL by CSharp or VB.Net for VBA
18.How to correctly reference and call a DLL
19.Email address validation by Regular Expressions using VBA
20.Fix MS Access error: Query must have at least one destination field
21.How to unselect radio buttons in MS Access after it has been selected
22.How to Change Query Timeout Value for MS Access SQL Queries
23.What is Northwind Traders database

Copyright © 2017 All Rights Reserved.

This website is hosted by HostGator.

No portion may be reproduced without my written permission. Software and hardware names mentioned on this site are registered trademarks of their respective companies. Should any right be infringed, it is totally unintentional. Drop me an email and I will promptly and gladly rectify it.

Home | Feedback | Terms of Use | Privacy Policy