Assembly generation failed

Source: Internet
Author: User

Assembly generation failed

I added a business appearance layer to the PetShop4 program, and then added it to the business logic layer (PetShop. BLL) reference this Assembly, click "generate", and the following error occurs: "assembly generation failed-the referenced assembly has no strong name", because PetShop. BLL is a strongly-named assembly, which cannot be caused by common assembly.

 

So what is a strongly-named assembly? We know that in the past, development programs in Windows often encountered the famous "DLL Hell" problem, that is, the backward compatibility of dynamic link libraries. Before. Net was generated, Microsoft tried to solve the DLL Hell problem by using COM components, that is, using Guid to uniquely identify each COM component. However, in fact, using COM components (including version upgrades) is also quite troublesome: To Run COM components, they must be registered in the group table, re-compilation may damage the Guid, so that the program that originally referenced this COM component cannot run correctly.

 

In. Net, Microsoft introduced a new solution: Strong naming assembly (Strong Name) and the Global Assembly Cache (GAC) supporting it to solve this problem.

 

We know that ,. net uses four attributes: Name, Version, Culture, and PublicToken to uniquely identify an assembly. The first three attributes of different products (Name, Version, and Culture) the same situation may occur. As a result, the unique identification assembly can be placed on the PublicToken. The strongly-named Assembly uses RSA to ensure the uniqueness of the PublicToken, Because theoretically, the public/private key pairs generated by RSA are not duplicated .. . Net writes the specified public/private key pair to the Assembly during compilation of the translation project to ensure its uniqueness.

 

MSDN introduces Global Assembly Cache (GAC) as follows: every computer installed with a Common Language Runtime Library has a code cache within the computer called Global Assembly Cache. The Global Assembly cache stores an assembly that is specifically specified to be shared by several applications on the computer.

 

When developing general and non-shared programs, you only need to edit the Project to. DLL or. EXE without using a strongly-named assembly. However, if we develop a component library and framework, by forcibly naming the Assembly and deploying it to GAC, we can ensure that our Assembly will not have version problems.

 

So how to create a strongly-named assembly? The procedure is as follows:

 

Use the SN tool to generate a key pair. The tool is installed. in the Bin directory of the NET Framework SDK, use "SN-k [drive letter]: [directory for storing the key] [key name] in the command line. an snk statement can generate a key pair. For example, we use SN-k C: \ MySloutionKey. snk, which can be named MySloutionKey. the snk key pair file is generated in the C root directory. At this time, the key pair is not associated with the Project assembly. We need to open AssemblyInfo of the Project. cs file. This file has a list of Assembly properties, which are included by default when you create a project in Visual Studio. NET. Modify the attribute "AssemblyKeyFile" in the Code as follows: [assembly: AssemblyKeyFile ("C: \ MySloutionKey. snk")]

 

In this way, the project is compiled to generate a strongly-named assembly. According to the above statement, the solution to this error is as follows:

 

First, open the visual studio 2005 command prompt (start --> program --> microsoft visual studio 2005 --> visual studio tools --> visual studio 2005 command prompt), and enter: sn-k PetShop. IBLL. snk press enter to generate PetShop. IBLL. snk, find PetShop in path C: \ Program Files \ Microsoft Visual Studio 8 \ VC. IBLL. put the snk file in the root directory of the IBLL project, that is, the IBLL directory, and then open AssemblyInfo Of The BLL project. cs, add the following code lines to it: [assembly: AssemblyKeyFile ("PetSHop. IBLL. snk ")], and then regenerate PetShop. IBLL project, so that a strongly-named assembly is generated.

-------------------------------------------------------------------

 

Add a strong name to the DLL file without source codeIf the project references other dll files without source code, and the dll file is an assembly without a strong name, during compilation, errors such as "Assembly generation failed -- referenced Assembly 'xxxxxxxxxxxxxx' with no strong name" will occur. Here I reference Interop. scripting. dll assembly, which is not a strong name, you need to perform the following operations: 1. open the SDK Command Prompt window; 2. create a new random key pair: Sn-k Interop. Scripting. snk3. decompile the Target Assembly Ildasm Interop. Scripting. dll/out = Interop. Scripting. il3. recompile with strong name Parameters Ilasm Interop. Scripting. il/dll/resource = Interop. Scripting. res/key = Interop. Scripting. snk/optimize4. Verify the signature information Sn-v Interop. Scripting. dllOK. re-introduce the generated dll file to the project and compile it. Http://t.qq.com/baijialeyi6756

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.