meaton
Posts: 12
Joined: Wed May 17, 2006 3:19 am

C#/.NET COM classes

Not sure if I'm just missing something, but I have a COM class written in C# which I am unable to get the installer to register. I'm trying to get it to extract the registration information but it gives an error every time. My non C# classes register fine. I have both a dll and tlb file that need to be registered, are .NET classes not yet supported ? or am I missing something ?
gigi
Posts: 2103
Joined: Tue Apr 11, 2006 9:55 am
Contact: Website

Hi,

It will be very helpful to us if you can tell what error you get. Also note that your dll must export a function named "DllRegisterServer".

Regards,
Gigi
_________________
Gheorghe Rada
Advanced Installer Team
http://www.advancedinstaller.com
meaton
Posts: 12
Joined: Wed May 17, 2006 3:19 am

"The selected file could not be registered"

This is given when I try to set the Registration to "extract registration info"

.NET COM objects are not registered in the same manner as other com objects. When the object is built you get a seperate type library file from which the details are extracted. the .NET objects do not have the normal self-register DLL entry point.
gigi
Posts: 2103
Joined: Tue Apr 11, 2006 9:55 am
Contact: Website

Hi,

You can register a Type Library(*.tlb) in the "COM" page. In the next release AI will automatically detect the necessary information used to register a COM object.

Regards,
Gigi
_________________
Gheorghe Rada
Advanced Installer Team
http://www.advancedinstaller.com
brian
Posts: 39
Joined: Tue Nov 29, 2005 5:30 pm
Location: California, USA

Does anyone know if this feature has been added yet? I've also got a .net dll and type library that when I check the 'register' checkbox I get the same error. I'm using version 4.4.1. I'm DYING to get off of InstallShield. This is my last product to convert and it does COM Interop....
gigi
Posts: 2103
Joined: Tue Apr 11, 2006 9:55 am
Contact: Website

Hi,

We have this on our TODO list. I increase its priority. Until then you can use Regasm.exe tool to register .Net COM Classes. Please see:
http://msdn2.microsoft.com/en-us/library/tzat5yw6.aspx

To register the .Net Classes using the Regasm.exe tool create a custom action in the "Custom Action" page.

Regards,
Gigi
_______________
Gheorghe Rada
Advanced Installer Team
http://www.advancedinstaller.com
brian
Posts: 39
Joined: Tue Nov 29, 2005 5:30 pm
Location: California, USA

Thanks. For those that are interested, here's how I did it, it's pretty easy to do, but not so intuitive to sift through the details:
1. Create a file search for RegAsm.exe, this will be used to register. Make the name REGASM, Use path=[WindowsFolder]Microsoft.Net\Framework, Set depth=5. Set the Min and Max Version to the runtime you want, I'm using 2.0 so I set min and max to 2.0. You need this for computers that have 1.0, 1.1, and 2.0 installed.

2. Create a new custom action of type "EXE with path given by propert" in the install commit. Set the property name to [REGASM] from above. Set the the command line to "[#yourfile.dll]" /tlb /codebase (be sure to use the quotes).

I'm not sure the absolute correct way, but I chose Synchronous execution ignore return code. Commit.

3. Do another custom action similar to 2 above, but put it in the Uninstall. This will be good for your installer to do to clean things up as step 2 creates a type library that won't be removed by uninstall without this step. In the Command line of the unistall action put "[#yourfile.dll]" /unregister

You'll also want to make sure that the installer either checks for or installs the appropriate .Net runtime or regasm won't be there.

Hope this helps someone.

Brian
dbalsbaugh
Posts: 26
Joined: Mon Dec 11, 2006 10:41 pm

Brian,

Thanks for the instructions, they were very helpful. One question, do you know if there is a way to hide the DOS window from popping up during the Custom Action install? I think it takes away from the general impression that people will get when they see these things popping up during an install or uninstall.

Thanks,

Dan
brian
Posts: 39
Joined: Tue Nov 29, 2005 5:30 pm
Location: California, USA

Boy, if you figure out how to not get the DOS window to pop up, please let me know. I've got three of them popping up and would love for them to go away. They're all .NET commandline applications. I was starting to ponder making them a .NET dll and call into functions within them?
gigi
Posts: 2103
Joined: Tue Apr 11, 2006 9:55 am
Contact: Website

Hi,

There is a similar approach about this on the forum please see:
http://www.advancedinstaller.com/forums ... en+command

Best Regards,
Gigi
______________
Gheorghe Rada
Advanced Installer Team
http://www.advancedinstaller.com
dbalsbaugh
Posts: 26
Joined: Mon Dec 11, 2006 10:41 pm

That worked great!

Thanks Gigi.
brian
Posts: 39
Joined: Tue Nov 29, 2005 5:30 pm
Location: California, USA

The previous thread doesn't work for me, the DOS window pops up. I'm not running batch files, I'm running exe files (regasm.exe is one). Does anyone know of a way to hide the DOS window that calls REGASM.EXE when registering a dll like this?
dbalsbaugh
Posts: 26
Joined: Mon Dec 11, 2006 10:41 pm

I created a CustomAction which calls a .vbs file during the Commit process. The vbs file looks something like this...

const WindowStyleStealth = &H20000000
set WSO = createobject("WScript.Shell")
WSO.run "%comspec% /c regasm.exe ASSEMBLY_FILE_NAME.dll", WindowStyleStealth, true

You will need to include the vbs file as an installed file.

This got rid of the DOS windows popping up for me.

Dan
brian
Posts: 39
Joined: Tue Nov 29, 2005 5:30 pm
Location: California, USA

Thanks. Doing this through a vbs like this, I don't understand how this works for you? I've tried this on many different computers and it doesn't work.

I'm thinking you must have included regasm.exe in your installation? Calling a vbs or a batch file like this will only work if regasm.exe is in the current folder where this vbs is being executed from.

The way this should work is to set up an environment variable on the computer (ie, %dotnetfolder%) and then use that in the vbs

WSO.run "%comspec% /c %dotnetfolder%regasm.exe YOUR_ASSEMBLY_HERE.dll /tlb /codebase", WindowStyleStealth, true

Brian
dbalsbaugh
Posts: 26
Joined: Mon Dec 11, 2006 10:41 pm

RegAsm.exe is part of the .NET Framework runtime. You should be able to path this out to "%WINDIR%\Microsoft.NET\Framework\v2.0.50727\RegAsm.exe". Assuming you are using 2.0 framework.

In my case, I have to also use gacutil.exe which is not part of the runtime so I was forced to install regasm.exe and gacutil.exe in my msi.

Return to “Common Problems”