|
|
|
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.
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.
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! |
|
Copyright © 2013 GeeksEngine.com. All Rights Reserved. This website is hosted by LunarPages. 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 |