<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Determining Whether a File Is an Assembly</title><link>http://blogs.msdn.com/suzcook/archive/2004/03/17/determining-whether-a-file-is-an-assembly.aspx</link><description>A file is an assembly if and only if it's managed and it contains an Assembly entry in its CLR metadata. Determining by hand A fast way to determine whether a file is an assembly is to run ildasm.exe on it. If it immediately gives an error saying that</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>New and Notable 40</title><link>http://blogs.msdn.com/suzcook/archive/2004/03/17/determining-whether-a-file-is-an-assembly.aspx#91860</link><pubDate>Thu, 18 Mar 2004 15:41:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:91860</guid><dc:creator>Sam Gentile's Blog</dc:creator><description /></item><item><title>re: Determining Whether a File Is an Assembly</title><link>http://blogs.msdn.com/suzcook/archive/2004/03/17/determining-whether-a-file-is-an-assembly.aspx#92148</link><pubDate>Thu, 18 Mar 2004 18:40:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:92148</guid><dc:creator>Ilya Ryzhenkov</dc:creator><description>How can I check if the file is an assembly WITHOUT loading an assembly from managed code? For example, to present user with list of available plug-ins.</description></item><item><title>re: Determining Whether a File Is an Assembly</title><link>http://blogs.msdn.com/suzcook/archive/2004/03/17/determining-whether-a-file-is-an-assembly.aspx#92160</link><pubDate>Thu, 18 Mar 2004 19:06:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:92160</guid><dc:creator>Suzanne</dc:creator><description>If you call AssemblyName.GetAssemblyName() (except in v1.0 SP2 - will be fixed in SP3), it will return an AssemblyName if it's a valid assembly, or throw a BadImageFormatException if not. The file will be loaded and then immediately released after data is retrieved. So, it won't cause the assembly to remain locked.&lt;br&gt;&lt;br&gt;Another option is to do the loading in a separate AppDomain, which you unload when you're finished.&lt;br&gt;</description></item><item><title>re: Determining Whether a File Is an Assembly</title><link>http://blogs.msdn.com/suzcook/archive/2004/03/17/determining-whether-a-file-is-an-assembly.aspx#93774</link><pubDate>Mon, 22 Mar 2004 08:46:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:93774</guid><dc:creator>Omer van Kloeten</dc:creator><description>Why do I have to use a way that returns an exception if it fails?&lt;br&gt;Why not return a boolean for an Assembly.IsAssemblyFile(string) method or something?&lt;br&gt;Exceptions cost too much...</description></item><item><title>re: Determining Whether a File Is an Assembly</title><link>http://blogs.msdn.com/suzcook/archive/2004/03/17/determining-whether-a-file-is-an-assembly.aspx#94071</link><pubDate>Mon, 22 Mar 2004 19:41:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:94071</guid><dc:creator>Suzanne</dc:creator><description>Opening the file when it will not later be used is not optimal for performance, either. IMHO, if perf is a concern, then the IsAssemblyFile() question should not be asked by the app at all. That app should make it so that they can assume it's an assembly (or that it's not), without having to test it. One way to do that is by having the user specify the assembly or assemblies that s/he cares about. In that case, if it turns out to not be an assembly when it's supposed to be, then it's an 'exceptional' situation, and can fail as appropriate.&lt;br&gt;</description></item><item><title>re: Determining Whether a File Is an Assembly</title><link>http://blogs.msdn.com/suzcook/archive/2004/03/17/determining-whether-a-file-is-an-assembly.aspx#94488</link><pubDate>Tue, 23 Mar 2004 12:55:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:94488</guid><dc:creator>Omer van Kloeten</dc:creator><description>I agree with you when talking about normal situations. However, a situation I can present you with as a good example is when you want to list all assemblies in a certain directory.&lt;br&gt;Listing .DLL and .EXE files isn't enough, since you can't be sure they're all assembly files.&lt;br&gt;This situation could benefit from such a method, since there is an iteration on the files and an exception slows down the process.</description></item><item><title>If it's a .dll or .exe, it's an assembly, right??</title><link>http://blogs.msdn.com/suzcook/archive/2004/03/17/determining-whether-a-file-is-an-assembly.aspx#257692</link><pubDate>Mon, 15 Nov 2004 21:21:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:257692</guid><dc:creator>Javier G. Lozano</dc:creator><description /></item><item><title>re: Determining Whether a File Is an Assembly</title><link>http://blogs.msdn.com/suzcook/archive/2004/03/17/determining-whether-a-file-is-an-assembly.aspx#443279</link><pubDate>Tue, 26 Jul 2005 07:28:56 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:443279</guid><dc:creator>Joseph</dc:creator><description>I have assemblies that are strong named and therefore MUST be managed. When I run Ildasm.exe, I get the PE exception. Therefore, I don't believe that your blog entry is accurate as perfectly valid, strong named, managed assemblies also get the PE exception. If you have further comments on this, I would greatly appreciate them as I am trying to find an accurate way to determine whether an assembly is managed or not. Thanks and I like your blog!</description></item><item><title>re: Determining Whether a File Is an Assembly</title><link>http://blogs.msdn.com/suzcook/archive/2004/03/17/determining-whether-a-file-is-an-assembly.aspx#443653</link><pubDate>Wed, 27 Jul 2005 03:43:40 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:443653</guid><dc:creator>Suzanne Cook</dc:creator><description>Omer: My point was that I recommend a design where needing to check all the files in a dir is unnecessary. So, yes, that is a situation where you would want an IsAssemblyFile(), but my point was that you should avoid that situation in the first place, for the reasons I gave in my earlier responses.&lt;br&gt;&lt;br&gt;Joseph: It's hard to tell what caused the exception without more info. But, it sounds so far that the file is corrupt, not a valid, strongly-named, managed assembly, or else ildasm would have been able to load it. Try running peverify.exe on it.&lt;br&gt;</description></item><item><title>re: Determining Whether a File Is an Assembly</title><link>http://blogs.msdn.com/suzcook/archive/2004/03/17/determining-whether-a-file-is-an-assembly.aspx#488311</link><pubDate>Wed, 02 Nov 2005 20:59:19 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:488311</guid><dc:creator>Rupreet Singh Gujral</dc:creator><description>I wrote this code through which we can determine programmatically whether a file is a .NET assembly or not - all managed way.&lt;br&gt;&lt;br&gt;&lt;a rel="nofollow" target="_new" href="http://www.geekswithblogs.com/rupreet/archive/2005/11/02/58873.aspx"&gt;http://www.geekswithblogs.com/rupreet/archive/2005/11/02/58873.aspx&lt;/a&gt;&lt;br&gt;</description></item></channel></rss>