About assembly generation failure--referenced assemblies have no strong name resolution

Source: Internet
Author: User

I added a business façade layer to the PETSHOP4 program and then referenced the assembly at the business Logic layer (PETSHOP.BLL), and then "build", the following error occurred: "Assembly build failed-- referenced assembly does not have a strong name", Because PETSHOP.BLL is a strong-named assembly, strong-named assemblies cannot be caused by ordinary assemblies.

So what is a strong-named assembly? We know that the previous development program under Windows often encounters the famous "DLL Hell" problem, which is the backward compatibility of the dynamic link library. Microsoft in the. NET generated before attempting to use COM components to solve DLL hell problems, that is, using GUIDs to uniquely identify each COM component. However, actually using COM components, including version upgrades, is also a hassle: In order to run a COM component, it must be registered in the Group Book table, recompiling could corrupt the GUID, causing the program that originally referenced the COM component to run incorrectly, and so on.

In. NET, Microsoft introduced a new solution: strong-Named Assemblies (strong name), and the accompanying global assembly cache (GAC) to address this issue.

We know. NET uses the Name, Version, Culture, and Publictoken four properties to uniquely identify an assembly, while the first three properties of different products (Name, version, and Culture) are identical in the case of a possible occurrence, so that This unique identity assembly can be a heavy burden on the head of Publictoken. Strong-Named assemblies use RSA to ensure the uniqueness of the Publictoken, because in theory the non-symmetric algorithm RSA generates a public/private key pair that is not duplicated. NET is to guarantee its uniqueness by writing the specified public/private key pair to the assembly when compiling the project.

For the global assembly Cache (GAC), this is described by MSDN: Each computer that has the common language runtime installed has a computer-wide code cache called the global assembly cache. The global assembly cache stores assemblies that are specifically assigned to shared by several applications in the computer.

When developing generic, non-shared programs, we do not need to use strong-named assemblies, only the projects (project) can be edited into. dlls or. exe. However, if we are developing a component library, a framework, by strongly naming the assemblies and deploying them to the GAC, we can guarantee that our assemblies will not have a version problem.

So, how do you create a strongly named assembly? The following are the steps

Use the SN tool to generate a key pair. The tool is located in the Bin directory where the. NET Framework SDK is installed, and you can generate a key pair in a command line using a statement such as "sn-k [Drive letter]:[the directory where the key is placed] [key name].snk"). For example, if we use sn-k C:\MySloutionKey.snk, we can generate a key pair file named Mysloutionkey.snk to the C packing directory, at which point the key pair is not associated with the project's assembly. We need to open the project's AssemblyInfo.cs file. This file has a list of assembly properties that are included by default when you create a project in Visual Studio. NET. Modify the property named "AssemblyKeyFile" in your 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, this error solves the problem as follows:

First open the Visual Studio 2005 command Prompt (Start-to-Program-->microsoft Visual Studio 2005-->visual Studio Tools-->visual Studio 2005 command Prompt), in which enter: Sn-k PetShop.IBLL.snk Enter, this generates PETSHOP.IBLL.SNK, in the path C:\Program Files\Microsoft Visual Studio 8\VC Find PetShop.IBLL.snk file, put in the root directory of the IBLL project, which is the IBLL directory, and then open the AssemblyInfo.cs of the BLL project, add the following line of code: [Assembly:assemblykeyfile (" PetSHop.IBLL.snk ")], and then regenerate the PETSHOP.IBLL project so that a strong named assembly is generated.

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

add a stronger name to a DLL file that does not have a source codeIf the project references other DLL files that do not have a source code, and this DLL file is an assembly that does not have a strong name, an error such as "Assembly generation failed-referenced assembly ' xxxxxxxxxxx ' no Strong name" appears at compile time. I'm referring to the Interop.Scripting.dll assembly, which is not a strong name, you need to do the following: 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 named parameters ILAsm interop.scripting.il/dll/resource=interop.scripting.res/key=interop.scripting.snk/optimize4. Verifying signature Information sn-v Interop.Scripting.dllOK, re-introduce the generated DLL file into the project and compile. http://t.qq.com/baijialeyi6756

About assembly generation failure--referenced assemblies have no strong name resolution

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.