Strong Name (2) refers to an assembly with a strong name signature

Source: Internet
Author: User

The process of referencing a strong named assembly is transparent to us and requires no additional effort. You can verify the role of a strong-named assembly in this way.

First, create a class library project Strongnamereferencelib and sign it strongly.

Figure 9-16 referencing a strong named assembly

Next, modify the StrongName project you created earlier to refer to the Strongnamereferencelib project (Figure 9-16) and invoke its Gethello method.

The main code for the Strongnamereferencelib project is shown in code listing 9-6.

Code listings 9-6 Strongnamereferencelib Project main code

Using System;
Using System.Collections.Generic;
Using System.Linq;
Using System.Text;
     
Namespace Strongnamereferencelib
{public
    class Class1
    {public
        static string Gethello ()
        {
            return "Hello";}}

See more highlights of this column: http://www.bianceng.cnhttp://www.bianceng.cn/Programming/net/

The modified StrongName project code is shown in code listing 9-7.

Code Listings 9-7 StrongName Project Code

Using System.Text;
Using System.Reflection;
Using Strongnamereferencelib;
     
Namespace StrongName
{
        
    class program
    {
        static void Main (string[] args)
        {
          Console.WriteLine (  Class1.gethello ());
               
            Console.read ();}}

Recompile the StrongName project and get the new StrongName.exe file. Use ILDASM to open the StrongName.exe file and view its assembly manifest, as shown in Figure 9-17.

Figure 9-17 StrongName.exe assembly Manifest

As you can see from the assembly manifest, it refers to two assemblies with strong name signatures: mscorlib and (newly created) Strongnamereferencelib, adding versions and PublicKeyToken identities to two assemblies.

Below, remove the strong name signature of the Strongnamereferencelib, recompile the project, but do not recompile the StrongName project. Replace the StrongName.exe reference StrongNameReferenceLib.dll with the newly generated StrongNameReferenceLib.dll to see what happens. The result is shown in Figure 9-18.

Figure 9-18 StrongName Project Replacement DLL then the result

As you can see from the exception information in Figure 9-18, the StrongName project cannot find a matching assembly. The reason is that the PublicKeyToken value is stored in the StrongName assembly manifest, and the item without a strong name signature does not have the attribute.

Author: Hyun-Soul

Source: http://www.cnblogs.com/xuanhun/

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.