Microsoft Knowledge Base Article
This article contents is Microsoft Copyrighted material.
©2005-©2007 Microsoft Corporation. All rights reserved.
Terms
of Use |
Trademarks
Article ID: 915589 - Last Review: December 3, 2007 - Revision: 1.2
Description of a documentation error in the "Assembly.Load Method (Byte[])" topic in the .NET Framework Class Library online documentation
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:
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>
/// 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");
}
}
}
- 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>
/// Summary description for Class1
/// </summary>
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.
APPLIES TO
- Microsoft .NET Framework 2.0
- Microsoft .NET Framework 1.1 Service Pack 1
Community Feedback System
Very often, it takes hours to solve a problem. Very often, you've looked high
and low, and have tried a lot of solutions. When you finally found it, chances
are, it was because someone else helped you. Here's your chance to give back.
Use our community feedback tool to let others know what worked for you and what
didn't.
Please also understand that the community feedback system is not warranted to be
correct, it's simply a system that we've built to let people try and help each
other. If something in a feedback response doesn't make sense to you, or you're
not comfortable making changes that the feedback talks about (like registry
edits), please consult a professional.
Thank you for using kbAlertz.com Feedback System.
-- Scott Cate
Be the first to leave feedback, to help others about this knowledge base
article.
(Optional) Name
(Optional)
Public URL Or Email
Comments
No
HTML -- Text Only Please