Registering the .NET ActiveX

转: http://www.sweetpotatosoftware.com/SPSBlog/PermaLink,guid,df3f1be8-62bc-491c-935e-570ebfe53164.aspx

Problems with registering
I received a few comments and a couple of emails regarding how to properly register the ActiveX Menustrip/Toolstrip. The problem is that even after registering the control with RegAsm, the developer gets either an error about the control not being registered or an error about a specified file not being found. The second of these error messages is closer to the truth, since the problem is that even though the control is registered the system can't find the assembly. Now there are a few ways you can fix this, some are better than others.

First way (definitely a bad idea)
The first way to do this is to put it in the Global Assembly Cache (GAC) which has two problems, it's a bad idea to be gunking up your (or your customers) GAC with a bunch of home-grown assemblies and since the original release I put out for download is not signed with a strong name it won't work.

Second way (probably a bad idea)
The second way to do this is to use the /codebase switch with regasm.exe. To find out what the codebase switch does you can read about it at Assembly Registration Tool. The basic command line command to do this:

regasm /codebase dotnetcontrol.dll

Just in case you don't know, you may need to include the full path to both regasm and the dotnetcontrol.dll in the command above. So for you it might be something more like:

C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\regasm.exe /codebase C:\DotNetControl\DotNetControl.dll

The problem with this approach is that since the assembly (dotnetcontrol.dll) isn't signed with a strong name you'll get a scarey message like the following when you run register the assembly with the /codebase switch:

RegAsm : warning RA0000 : Registering an unsigned assembly with /codebase can ca
use your assembly to interfere with other applications that may be installed on
the same computer. The /codebase switch is intended to be used only with signed
assemblies. Please give your assembly a strong name and re-register it.
Types registered successfully

Now, I personally think the warning message is a little overblown, but if they say that the /codebase switch should only be used for assemblies with a strong name then let's move on to the third way to do this.

Third way
Download the assembly I've rebuilt. It is signed with a strong name so you can use the /codebase switch without getting that scarey message above. If you've already registered the one from my previous blog entry then unregister it. Then register this new one using the same steps given in the second way I presented above.

How to sign an assembly with a strong name
For those of you that are working with the C# project and would like to know how to sign your assembly with a strong name, you can read about it in Signing an Assembly with a Strong Name. Basically the easiest way to do it is to use sn.exe (comes in the SDK) to create a strong name key file (.SNK). Then put that strong name key file in your project somewhere. Finally open up the AssemblyInfo.cs file in your project and put the following line at the bottom of it (you need either the fullpath or relative path to the key file inside the quotes):

[assembly:AssemblyKeyFileAttribute(@"sgKey.snk")]

Now you can rebuild your assembly and it will be signed with a strong name.

Parting thoughts
When creating controls or examples with .NET whether it be an FLL, an ActiveX control, or whatever it pays to take the time to map out the steps for properly installing the runtimes or registering the control. A few extra minutes on my part could have saved some of you precious time. You have my apologies and I think I've learned my lesson this time. Special thanks to Bernard Bout and Gary Williams for being the first two developers to bring this issue to my attention.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值