Share via


Getting assembly version of dll files in a directory

Question

Friday, June 7, 2013 9:55 AM

Good morning.

I am iterating a directory, including sub-folders, and trying to get the assembly version of .dlls contained in the directory.  For the most part, this is working, except I come across the error below:

"Could not load file or assembly XXX or one of its dependencies.  The module was expected to contain an assembly manifest."

I have tried using Assembly.LoadFrom(path) and Assembly.ReflectionOnlyLoadFrom(path).

What other alternatives do I have?  Can I get the assembly information without first loading the assembly?

I know that I could use FileVersion, but that may not contain the information that I need.

Any assistance would be GREATLY appreciated!  Thank you.

Regards,

Chris

All replies (6)

Friday, June 7, 2013 3:43 PM âś…Answered

"Could not load file or assembly XXX or one of its dependencies.  The module was expected to contain an assembly manifest."

Ok, I missed this one. Your error message is telling you, that your dll file is missing an assembly manifest and the method System.Reflection.AssemblyName.GetAssemblyName() depends on a valid assembly manifest. But, since those manifests contain all the assembly metadata (such as assembly name, version, culture etc.), I suppose, that you won't get any version infos of those files giving you that error.

wizend


Friday, June 7, 2013 10:19 AM | 1 vote

Hi Chris,

this may be done that way:

AssemblyName.GetAssemblyName("assemblyName").Version

Friday, June 7, 2013 11:51 AM

Thanks for the quick reply, Jakob. I thought that I tried that, but encountered the same error. Does that method perhaps call one of the methods that I am using, under the covers? I will try it again and let you know. Thanks...Chris


Friday, June 7, 2013 12:05 PM

I think, you need to insert the fullname of your file, for instance:

Console.WriteLine("{0}", System.Reflection.AssemblyName.GetAssemblyName(@"C:\Windows\Microsoft.NET\Framework64\v4.0.30319\mscorlib.dll").Version);

wizend


Friday, June 7, 2013 2:13 PM

I tried using the code below:

System.Reflection.AssemblyName.GetAssemblyName(flInfo.FullName).Version.ToString()

flInfo.FullName gives me the UNC path to the .dll file.  I get the same error.


Friday, June 7, 2013 11:47 PM

OK.  Thanks, Wizend.

Thanks to you too, Jakob.