Strong programming naming and GAC

Source: Internet
Author: User

1. Create a project other and create the following classes:
Using system;
Using system. Collections. Generic;
Using system. text;

Namespace other. Global Application Cache
{
Public class GAC
{
Public String callgac ()
{
Return "GAC end ";
}
}
}

2. Strong namingProgramSet:
On the project other, right-click, sign, sign the assembly, and create or browse the key file.
You can also create a key in the SDK command prompt, Sn-k d: \ Companya. Keys, which is referenced here. Vs2003: [Assembly: assemblykeyfile

("D: \ Companya. Keys")]
Compile. At this time, other. dll is already a strongly-named assembly.

3. Shared Assembly other. dll:
Drag the Assembly (such as E: \ personal folder \ code \ enterprise application solution \ other \ bin \ debug \ other. dll) into the global application cache (such:

C: \ windows \ Assembly)
But it is also completed in the SDK command prompt, such as: gacutil/I E: \ personal folder \ code \ enterprise application solution \ other \ bin \ debug \ other. dll

4. Call the shared Assembly other. dll
Create a web project mywebproject and add and reference the just-created Assembly other. dll, for example, E: \ personal folder \ code \ enterprise application solution

\ Other \ bin \ debug \ other. dll. In this case, the Web. config of mywebproject contains:

<Compilation DEBUG = "true">
<Assemblies>
<Add Assembly = "Other, version = 1.0.0.0, culture = neutral,

Publickeytoken = 43fc64574884c304 "/> </assemblies> </compilation> </system. Web>
CallCodeAs follows:

Public partial class _ default: system. Web. UI. Page
{
Protected void page_load (Object sender, eventargs E)
{

}
Protected void button#click (Object sender, eventargs E)
{
// Use reflection without reference
System. reflection. Assembly = system. reflection. Assembly. Load ("Other, version = 1.0.0.0, culture = neutral, publickeytoken = 43fc64574884c304 ");
This. response. Write ("Using Reflection to load assembly from GAC" + assembly. globalassemblycache );

}
Protected void button2_click (Object sender, eventargs E)
{
// Must be referenced. After the mywebproject of the website is deployed, you can delete the call E: \ personal folder \ code \ enterprise application solution.

\ other \ bin \ debug \ other. DLL
Other. global Application cache. GAC = new other. global Application cache. GAC ();
string result = GAC. callgac ();
This. response. write (result);
}< BR >}

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.