views:

60

answers:

1

I wrote some sample code like this, all the outputs are the same, which is weird for me,

I guess it makes sense if assembly1 is as same as assemly2, since the assembly information is the same(such as name, assembly version, GUID and etc.)

however, I changed the assembly information and recompile the SampleCodedFormula.dll(then rename it to Changed-assemply-info-and-recompile-SampleCodedFormula.dll), surprisingly, the assembly3 output is still same as assembly1.

assembly1,2,3 are compiled from the same codebase.

Can anyone tell me why the behavior is like this? does it make sense to you?

var domain = AppDomain.CurrentDomain;
var assembly1 = domain.Load(AssemblyName.GetAssemblyName("c:\\SampleCodedFormula.dll"));
Console.WriteLine(assembly1.CodeBase);
Console.WriteLine(assembly1.GetExportedTypes()[0]);

var assembly2 = domain.Load(AssemblyName.GetAssemblyName("c:\\Copied-From-SampleCodedFormula.dll"));
Console.WriteLine(assembly2.CodeBase);
Console.WriteLine(assembly2.GetExportedTypes()[0]);


var assembly3 = domain.Load(AssemblyName.GetAssemblyName("c:\\Changed-assemply-info-and-recompile-SampleCodedFormula.dll"));
Console.WriteLine(assembly3.CodeBase);
Console.WriteLine(assembly3.GetExportedTypes()[0]);
+1  A: 

Just by checking verstion of assembly like this

 // get the version object for this assembly
        Version v = System.Reflection.Assembly.GetExecutingAssembly().
         GetName().Version;

or

Use the FileVersionInfo object. Here's an example from the Microsoft website that gets the version info from notepad.exe

public void GetFileVersion() {
    // Get the file version for the notepad.
    FileVersionInfo myFileVersionInfo = FileVersionInfo.GetVersionInfo("%systemroot%\\Notepad.exe");

    // Print the file name and version number.
    textBox1.Text = "File: " + myFileVersionInfo.FileDescription + '\n' +
       "Version number: " + myFileVersionInfo.FileVersion;
 }
Pranay Rana