How to use this article to solve our project's reference to a generic COM component: Strong Name When referencing the activex/com component

Source: Internet
Author: User
Tags dotnet reference wrapper visual studio
active|activex| resolution  csharp Tips: Strong name     When referencing activex/com components select from Mittermeyer Blog   Problem Dotnet platform provides a relatively complete class library, but the first version is never exhaustive, and due to historical problems, often with Com/activex components interoperability. The problem with the author is to call an object in Excel in a assembly, but the Assembly needs to be encapsulated as an ActiveX control for client script calls from IE. In short, I used a COM component in C #, and I needed to encapsulate myself as a COM component, which sounded a little redundant but couldn't think of a better way. A problem with this encapsulation mode is that if a assembly wants to be encapsulated as a activex/com component, it must have a strong name (strong name), which means that the SNK (strong name Key) needs to be specified at compile time. But when a assembly is compiled with a strong name, it also requires that all other assembly referenced by itself must have a strong name, otherwise it cannot be compiled successfully. And when we refer directly to a COM component (for example, Excel Object Library) in engineering, VS. NET can help us to automatically import the type library, but at this point the reference type library is not strong and cannot compile successfully in the environment I expect.   Solve this problem feel very tricky, seems to fall into and dead loop, but look up the document, found that it is very easy to solve, the dotnet framework provides the appropriate tools to convert the COM type library, he is TlbImp.exe (everyone can be in the similar "C : \program Files\Microsoft In the directory of Visual Studio. NET 2003 dk\v1.1. TlbImp can wrap a COM component into the form of a class library that dotnet can use, VS. NET's automatic conversion presumably also since this tool. The tool has a number of parameter switches that require support for a strong name as long as an extra switch is turned on. What I think is most likely to use the parameters:/out:filename: The name of the output file after the type library transformation. /namespace:namespace: The namespace used by the type library transformation. /keyfile:filename: Specifies the SNK file to use when converting, indicating the type after constructionThe library has a strong name. The complete example is as follows: TlbImp excel.exe/out:interop.excel.dll/namespace:excel/keyfile: Excel.snk where the SNK file can be generated by another tool SN in dotnet, this is not the place to repeat. By doing this, you can successfully compile a strong-named DLL by referencing our own constructed type library directly in the project.   If it's a control, not a normal component, then you can't use TlbImp, and you need to use the AxImp.exe tool, which is similar to tlbimp, and he generates two files: one is the proxy file for the type library and the other is the Windows The proxy file for the form.   Further solutions there is a simpler solution, however, to set the "wrapper Assembly key File" (Common properties\general\wrapper Assembly key file) in the engineering properties. This property. The Com/activex component that is added through Add reference after the property is set is identified and has a strong name. This needs to be set one at a time, it should be more convenient.    reference Documentation TlbImp Related: http://msdn.microsoft.com/library/en-us/cptools/html/ CPGRFTYPELIBRARYIMPORTERTLBIMPEXE.ASPSN Related: http://msdn.microsoft.com/library/en-us/cptools/html/ Cpgrfstrongnameutilitysnexe.aspaximp Related: http://msdn.microsoft.com/library/en-us/cptools/html/ Cpgrfwindowsformsactivexcontrolimporteraximpexe.aspc# Engineering Description of the property: http://msdn.microsoft.com/library/en-us/cscon/ Html/vcurfcprojectgeneralpropertypage.asp

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.