Microsoft KB Archive/915589

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

Article ID: 915589

Article Last Modified on 12/3/2007

-

APPLIES TO


 * Microsoft .NET Framework 2.0
 * Microsoft .NET Framework 1.1 Service Pack 1

-





INTRODUCTION
The &quot;Assembly.Load Method (Byte[])&quot; topic in the Microsoft .NET Framework Class Library online documentation contains an error. Under the heading &quot;Remarks,&quot; 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

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:  Create a Microsoft Windows application project that has a strong name by using Microsoft Visual Studio 2005 or Microsoft Visual Studio .NET.  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 description for Form1 ///    public class Form1 : System.Windows.Forms.Form {       private System.Windows.Forms.Button button1; ///        /// Required designer variable ///        private System.ComponentModel.Container components = null;

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

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

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

#region Windows Form Designer generated code ///        /// Required method for Designer support - do not modify /// the contents of this method with the code editor ///        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 = &quot;button1&quot;; this.button1.Size = new System.Drawing.Size(96, 40); this.button1.TabIndex = 0; this.button1.Text = &quot;button1&quot;; 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 = &quot;Form1&quot;; this.Text = &quot;Form1&quot;; this.ResumeLayout(false);

}       #endregion

///        /// The main entry point for the application ///        [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(@&quot;C:\evidence1.txt&quot;, System.IO.FileMode.Create); StreamWriter outStream = new StreamWriter(fs); outStream.AutoFlush = true; Console.SetOut(outStream);

Console.WriteLine(&quot;Current AppDomain {0} :&quot;,AppDomain.CurrentDomain.FriendlyName); Console.WriteLine(&quot;Current evidence of {0} :&quot;, 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(@&quot;c:\Assembly1.dll&quot;); }   } }  Add a new library project that has a different strong name, and then name the project Assembly1.  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 description for Class1 ///    public class Class1 {       public Class1 {           //            // TODO: Add constructor logic here //       }    } }  Run the application, and then verify the strong names.

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

Keywords: kbhowto kbinfo KB915589

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.