C# .NET - How to read assembly version no ? - Asked By Amit Choudhary on 02-Jan-07 05:17 AM

Hi,

How to read assembly version no without loading Assembly in memory. As we r using this code

 

System.Version  objVersion =System.Reflection.Assembly.LoadFile(FilePath).GetName().Version;
MessageBox.Show(objVersion.ToString());
But this will load file in memory which will not let us replace this assembly.
Can any one tell the way to read version no or unload assembly from  memory ?
Thx in advance 
Amit Choudhary 
 
 
 
 

System.reflection.assembly - Venkat K replied to Amit Choudhary on 02-Jan-07 06:20 AM

public string strVersion = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString();

AppDomain - sundar k replied to Amit Choudhary on 02-Jan-07 06:37 AM


You should use AppDomain Load and Unload for doing that,

Application domains, which are represented by AppDomain objects, provides isolation, unloading, and security boundaries for executing managed code. Application domains are created using the CreateDomain method. AppDomain instances are used to load and execute assemblies (Assembly). When a AppDomain is no longer in use, it can be unloaded.

For more details, you should read the below article on,

Why isn't there an Assembly.Unload method?
http://blogs.msdn.com/jasonz/archive/2004/05/31/145105.aspx

Once an assembly is loaded into an AppDomain - Peter Bromberg replied to Amit Choudhary on 02-Jan-07 07:48 AM

it cannot be unloaded. What you probably need to do is read the metadata from the assembly  first. What is the goal here? Normally one would simply have the correct version of the assembly present.
Goal is to compare versions and replace dll - Amit Choudhary replied to Peter Bromberg on 02-Jan-07 07:59 AM
but if dll is loaded in memory then it won't let me replace dll , which is happening during version no reading for comparasion.
Take a look at the AppDomain.ReflectionOnlyXXX methods - Peter Bromberg replied to Amit Choudhary on 02-Jan-07 09:08 AM

These load assemblies into the ReflectionOnly portion of the AppDomain, without executing any ctors or initialization code. You can then inspect the assembly version and decide whether to load the assembly normally.


hitesh jain replied to Amit Choudhary on 31-Aug-09 12:32 AM
Too late reply.
but this with help others

AssemblyName assemblyName = AssemblyName.GetAssemblyName(assemblyPath);
version = assemblyName.Version.ToString();

This will not load the assembly in memory.
Thanks - Abhijeet Kumar replied to hitesh jain on 26-Oct-09 03:00 AM
Hi i was searching this code . This is very helpful for me thank you very much.



With Regards
Abhijeet Kumar
India