If you're registering your .NET assembly for use in COM, there are a couple of traps that you should be aware of.
You create a class library, make your nifty class you want to instantiate from JavaScript, and compile it. Then you open up the bin folder in Visual Studio Command Prompt:
regasm.exe MyControls.dll
But it doesn't seem to do anything.
""RegAsm : warning RA0000 : No registry script will be produced since there are no
types to register."
There are three things to check if this happens.
- Make sure your library marked ComVisible. Open up AssemblyInfo.cs, and make sure you have [assembly: ComVisible(True)]. If you only want a specific class to be visible, put a [ComVisible(True)] attribute above the class.
- Make sure your class is public.
- This is the one that seems to catch people off guard. You must have a parameterless constructor for your class. If you have added another constructor, be sure to explicitly declare the parameterless constructor.
After you've checked on those three items, the class should register successfully. Unless you set the ProgId attribute, the class by default will be "Namespace.ClassName."
Unfortunately, this may not be the end of it. If you want to use this within Internet Explorer, particularly if it's a nonvisible control, you may receive a warning about running unsafe ActiveX object. Even after you click the yellow bar at the top and tell it to run, it will fail:
"Automation server can't create object".
Searching around the Internet, I discovered that you need to implement the IObjectSafety interface. But the easiest solution is to give your assembly a strong name.