How to get version of an assembly

  • Thread starter Thread starter Martin Asselhoff
  • Start date Start date
M

Martin Asselhoff

Hello again,

oops, I overlooked this ng is in english. Need new glasses ;-)

Here my problem again.

For an updateing process i need to know a version of certain assemblies of
an application, which is to be updated.
How do i get this information in CF?

I would appreciate any hint.
Thx, Martin.
 
Using the System.Reflection.AssemblyName class. For example:-
Version assVer =
System.Reflection.Assembly.LoadFrom("something.dll").GetName().Version;

Peter
 
Peter hi
Using the System.Reflection.AssemblyName class. For example:-
Version assVer =
System.Reflection.Assembly.LoadFrom("something.dll").GetName().Version;

Do you know when the assembly unloads OR how to unload it manually?

Writing the above made me think of a second question... If you then use the
assembly (not via reflection but via directly creating an object from it),
will there be 2 copies of the dll loaded in memory??

Cheers
Daniel
 
There isn't a way to force unloading of the assembly AFAIK. If your
application already has the assembly loaded it should reuse this rather than
loading a 2nd copy. This method should only be used if you want to check a
specific version from a file path - if you want to check the version of the
current assembly use
System.Reflection.Assembly.GetExecutingAssembly().GetName().Version
or for the version of an assembly used to create a specific type used in
your app use
myObject.GetType().Assembly.GetName().Version

Peter

--
Peter Foot
Windows Embedded MVP
OpenNETCF.org Senior Advisor
www.inthehand.com | www.opennetcf.org
 
Thanks...

I'll be a bit more specific....

Imagine an EXE using a DLL (a) that uses a DLL (b) that uses a DLL (c)....

Code running in the leaf DLL (c) has to know the version of the EXE. The
only way I found of doing that is to Assembly.LoadFrom(exePath)...

So:
Is there an alternative way of achieving the above?
Assuming not, I don't know how to force unloading the assembly... Is that
bad?
And my afterthought was: Since the exe is already running does it actually
get loaded twice or am I worrying for nothing?

Cheers
Daniel

PS In another scenario my exe has to find out the versions of all the
subordinate DLLs. Still looking for a solution on that...
 
PS In another scenario my exe has to find out the versions of all the
subordinate DLLs. Still looking for a solution on that...

Did you write the DLL's yourself? Then it should be no problem to add a
property 'version' to the assemblies, so that they can return it by
themselves.

D.Barisch
 
Hi

Thanks for your suggestion... It may form the beginning of a solution...

I should elaborate on the requirement: The dlls are not known to the exe. It
knows of 1 or 2 which themselves use 2-3 which themselves use 3-4 dlls and
so on.... So what I was looking for is a way from a top level exe to find
the versions of all dlls loaded in its process space...

Cheers
Daniel
 
Back
Top