Help and Support
 

powered byLive Search

Description of a documentation error in the "Assembly.Load Method (Byte[])" topic in the .NET Framework Class Library online documentation

Article ID:915589
Last Review:December 3, 2007
Revision:1.2

INTRODUCTION

The "Assembly.Load Method (Byte[])" topic in the Microsoft .NET Framework Class Library online documentation contains an error. Under the heading "Remarks," the following information is incorrect:
When you use a Load method with a Byte[] parameter to load a common object file format (COFF) image, evidence is combined. Zone, Url and Site are inherited from the calling assembly, and Hash and StrongName are taken from the COFF assembly.
This information is correct only in the original release version of the Microsoft .NET Framework 1.1. In the Microsoft .NET Framework 2.0 and in the Microsoft .NET Framework 1.1 Service Pack 1 (SP1), this information is incorrect.

MORE INFORMATION

In the .NET Framework 2.0 and in the .NET Framework 1.1 SP1, the StrongName evidence is inherited from the calling assembly.

In the .NET Framework 2.0 and in the .NET Framework 1.1 SP1, you can use the Assembly.Load (Byte[], Byte[], Evidence) method instead of the Assembly.Load (Byte[]) method to supply the specified evidence manually. For more information, visit the following Microsoft Developer Network (MSDN) Web site:
http://msdn2.microsoft.com/en-us/library/aa329939(VS.71).aspx (http://msdn2.microsoft.com/en-us/library/aa329939(VS.71).aspx)
To demonstrate that the StrongName evidence is inherited from the calling assembly in the .NET Framework 2.0 and in the .NET Framework 1.1 SP1, follow these steps:
1.Create a Microsoft Windows application project that has a strong name by using Microsoft Visual Studio 2005 or Microsoft Visual Studio .NET.
2.In the Form1.cs file, replace the existing code with the following code, and then build the project.
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;

using System.Data;
using System.Reflection;
using System.IO;
using System.Security.Policy;

namespace TestStrongName
{
	/// <summary>
	/// Summary description for Form1
	/// </summary>
	public class Form1 : System.Windows.Forms.Form
	{
		private System.Windows.Forms.Button button1;
		/// <summary>
		/// Required designer variable
		/// </summary>
		private System.ComponentModel.Container components = null;

		public Form1()
		{
			//
			// Required for Windows Form Designer support
			//
			InitializeComponent();

			//
			// TODO: Add any constructor code after InitializeComponent call
			//
		}

		/// <summary>
		/// Clean up any resources being used
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if (components != null) 
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		#region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor
		/// </summary>
		private void InitializeComponent()
		{
			this.button1 = new System.Windows.Forms.Button();
			this.SuspendLayout();
			// 
			// button1
			// 
			this.button1.Location = new System.Drawing.Point(48, 120);
			this.button1.Name = "button1";
			this.button1.Size = new System.Drawing.Size(96, 40);
			this.button1.TabIndex = 0;
			this.button1.Text = "button1";
			this.button1.Click += new System.EventHandler(this.button1_Click);
			// 
			// Form1
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
			this.ClientSize = new System.Drawing.Size(292, 273);
			this.Controls.Add(this.button1);
			this.Name = "Form1";
			this.Text = "Form1";
			this.ResumeLayout(false);

		}
		#endregion

		/// <summary>
		/// The main entry point for the application
		/// </summary>
		[STAThread]
		static void Main() 
		{
			Application.Run(new Form1());
		}


		public void TestLoad( string assemblyFileName)
		{
			WriteEvidence(Assembly.GetExecutingAssembly());
			//Read file into a byte array
			FileStream fs = new FileStream (assemblyFileName, FileMode.Open);
			byte[] buffer = new byte[(int) fs.Length];
			fs.Read(buffer, 0, buffer.Length );
			fs.Close();

			//Load assembly using byte array
			Assembly assembly = Assembly.Load(buffer);
			WriteEvidence(assembly);
		}
		
		void WriteEvidence(Assembly asm)
		{
			System.IO.FileStream fs = new System.IO.FileStream(@"C:\evidence1.txt", System.IO.FileMode.Create);
			StreamWriter outStream = new StreamWriter(fs);
			outStream.AutoFlush = true;
			Console.SetOut(outStream);

			Console.WriteLine("Current AppDomain {0} :",AppDomain.CurrentDomain.FriendlyName);
			Console.WriteLine("Current evidence of {0} :", asm.FullName);
            
			Evidence myEvidence = asm.Evidence; 
			IEnumerator list = myEvidence.GetEnumerator();
			while (list.MoveNext())
			{
				Console.WriteLine(list.Current.ToString());
			}

			outStream.Close();
			fs.Close();
			StreamWriter standardOutput = new StreamWriter(Console.OpenStandardOutput());
			standardOutput.AutoFlush = true;
			Console.SetOut(standardOutput);
			outStream = null;
			fs = null;
		}

		private void button1_Click(object sender, System.EventArgs e)
		{
		
			TestLoad(@"c:\Assembly1.dll");
		}
	}
}

3.Add a new library project that has a different strong name, and then name the project Assembly1.
4.In the Class1.cs file, replace the existing code with the following code, and then build the project.
using System;
using System.Reflection;
using System.IO;
using System.Security.Policy;
using System.Collections;

namespace Assembly1
{
	/// <summary>
	/// Summary description for Class1
	/// </summary>
	public class Class1
	{
		public Class1()
		{
			//
			// TODO: Add constructor logic here
			//
		}
	}
}
5.Run the application, and then verify the strong names.

Note You will see that the strong names are the same.

APPLIES TO
Microsoft .NET Framework 2.0
Microsoft .NET Framework 1.1 Service Pack 1

Back to the top

Keywords: 
kbhowto kbinfo KB915589

Article Translations

 

Other Support Options

  • Need More Help?
    Contact a Support professional by E-mail, Online or Phone.
  • Customer Service
    For non-technical assistance with product purchases, subscriptions, online services, events, training courses, corporate sales, piracy issues, and more.
  • Newsgroups
    Pose a question to other users. Discussion groups and Forums about specific Microsoft products, technologies, and services.