regasm just doesn't work

5.2k views Asked by At

For every example of registering .NET COM objects in the web, I see the tool "regasm" for doing the job. Everybody does so!!!
But it never worked for me! I am tired of trying to overcome it! My only solution would be regsvr32, which requires a function which I could only define in C++.
Please tell me why wouldn't it just work!!!

Considering that it doesn't work on all 4 of my computers, plus 3 virtual machines, running Windows 7 down to 2000, can anyone show me a working example of a regasm call? I think I am an idiot.

3

There are 3 answers

3
Hans Passant On BEST ANSWER

Registering [ComVisible] .NET assemblies with Regsvr32.exe is not possible. It doesn't have the required DllRegisterServer entrypoint that Regsvr32 needs. You will have to make it work with Regasm.exe or a Setup project. The latter is necessary when you deploy your server to another machine.

There are few failure modes. Other than:

  • forgetting to use the /codebase option. Required if you don't deploy the assembly to the GAC, something you should not do on your dev machine.

  • using the wrong version of Regasm.exe. There are two on a 64-bit machine, the Framework64 directory contains the one you have to use if the client code is 64-bit.

  • running it from a command prompt that is not elevated. Regasm.exe writes to the HKLM hive of the registry, something that UAC actively prevents. That's an issue on Vista and Win7.

Just getting the assembly grossly wrong is of course possible too. Like not making one or more interfaces and/or classes [ComVisible].

0
Jockebocke On

One issue I encountered is:

The dll (previous version) has been installed in the GAC, and new Com callable classes and their interfaces do not appear in the new generated tlb file. Which is of course, because the tlb is genenerated based on the gac-older version.

When generating a .reg file, the new classes ProgID and interfaces IID are suddenly present, which is quite confusing.

/codebase is ignored for gac-hosted dll's, and not required when generating the tlb file.

0
Edwin O. On

Its possible, i had this challenge before, and i ran this code on cmd window and it worked I found out it depended on the version of .net framework the assembly was buit on copy and paste the code below

 %SystemRoot%\Microsoft.NET\Framework\v4.0.30319\regasm.exe MyAssembly.dll

Kindly vote if it works for you.