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 >}