This is something that I have actually done a fair bit of recently. You can use AssemblyName name = AssemblyName.Load(string assemblyFile) to retrieve the strong-name attributes of an assembly. The runtime will load the DLL temporarily, then release it immediately. However, I far prefer to go the route of avoiding 'loading' DLLs at all - STAY AWAY from reflection unless you intend to actually late-bind to your loaded DLLs. Reflection has far too many requirements to satisfy, if you only intend to read some information from the DLL. Remember, that reflection was designed for EXECUTING MSIL code dynamically, yes you can read all sorts of data out of the DLL, but in my opinion it's overkill.
My preferred approach is to treat the DLL as a data document, and read its meta-data using a library that understands the format of MSIL. Microsoft has a library for doing just this: Microsoft.Cci http://ccimetadata.codeplex.com/ Using this library, you can 'read' the DLL into an extremely descriptive object-model, and obtain any information from it that you desire (even more information that you can with reflection). One of the big advantages of this, is that because the DLL is NOT LOADED FOR BINDING, it doesn't need any of its dependencies (AssemblyName.Load doesnt either however...), and even more importantly - the DLL can have been built for a later version of the .net runtime, or different processor architecture! So, if your application is .net2, and it is given a .net4 assembly, you can still read out all the metadata, and present a nice error message which includes all your assembly-name information, and mention that it was built for an incompatible version of the .net framework (or however you want to handle it). If you use AssemblyName.Load, or Assembly reflection, you will get a runtime 'BadImageFormatException'... using Microsoft.Cci is as simple as this: MetadataReaderHost host1 = new PeReader.DefaultHost(); var module = host1.LoadUnitFrom(assemblyPath) as IModule; // grab the publicKeyToken... but you should probably check that PublicKeyToken isnt null, as it may not be strongly named string publicKeyToken = BitConverter.ToString(new List<byte>(module.ContainingAssembly.PublicKeyToken).ToArray()).Replace( "-", "").ToLower(); // grab the assembly name string assemblyName = module.ContainingAssembly.Name.Value; // grab the version Version assemblyVersion = module.ContainingAssembly.Version; // grab the culture string assemblyCulture = module.ContainingAssembly.Culture; Note: The MetadataReaderHost used to hold a lock on the assembly until GC collected these objects, but a recent checkin to Microsoft.Cci has implemented IDisposable on MetaDataReaderHost which will clean everything up - nice! Hope this helps. Adam Langley Senior Developer +64 9 486 9010 +64 21 884400 [email protected] www.winscribe.com -----Original Message----- From: pcristini [mailto:[email protected]] Sent: Tuesday, 28 September 2010 9:24 a.m. To: [email protected] Subject: [WiX-users] Reading Assembly Information I'm looking to read information about an assembly (version, culture, publickey, etc) from an assembly, and store those values in properties which will then be added to the application's config file. I'm going to be producing elements like this: <Plugin name="UserManager" assembly="Plugin.Users, Version=1.0.0.0, Culture=neutral, PublicKeyToken=9d04a1dca2c654ed" class="Plugin.Users.UserManagerPlugin" enabled="true" /> Is there any solutions out there for this? I've searched around a bit but can't find anything even close to what I'm looking to do. -- View this message in context: http://windows-installer-xml-wix-toolset.687559.n2.nabble.com/Reading-As sembly-Information-tp5576754p5576754.html Sent from the wix-users mailing list archive at Nabble.com. ------------------------------------------------------------------------ ------ Start uncovering the many advantages of virtual appliances and start using them to simplify application deployment and accelerate your shift to cloud computing. http://p.sf.net/sfu/novell-sfdev2dev _______________________________________________ WiX-users mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/wix-users ------------------------------------------------------------------------------ Start uncovering the many advantages of virtual appliances and start using them to simplify application deployment and accelerate your shift to cloud computing. http://p.sf.net/sfu/novell-sfdev2dev _______________________________________________ WiX-users mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/wix-users

