Problems with Version 3.4

Sep 27, 2013 at 12:49 AM
Edited Sep 27, 2013 at 1:06 AM
Hello James,
its me again ;-)
I think I found a serious bug in your new Version. The Bug is in Utilities.DataTypes.ExtensionMethods.ReflectionExtensions / Utilities.DataTypes.Conversion.Manager. In the Manager Class your are loading all dlls in the application path on startup. This is done in Utilities.DataTypes.ExtensionMethods.ReflectionExtensions.LoadAssemblies.
The Problem is, that there can be dlls in the Application Path that are no .NET dlls. I use for example List and Label (a Report Engine like Crytal Reports). This Report Engine has one .NET assembly and a bunch of (com?) dlls. If you try to load such a dll an exception is thrown (BadImageFormatException). I think you must do some sort of exception handling in this Extension Method ;-)
Another example is SevenZipSharp. Its a Wrapper around 7Zip. With this one you can easily test it. Just copy the 7z.dll into your test folder....
Maybe something like this:
        public static IEnumerable<Assembly> LoadAssemblies(this DirectoryInfo Directory, bool Recursive = false)
        {
            foreach (FileInfo File in Directory.GetFiles("*.dll", Recursive ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly))
            {
                Assembly assembly = LoadAssembly(File.FullName);
                if (assembly != null) yield return assembly;
            }
        }

        private static Assembly LoadAssembly(string FileName)
        {
            AssemblyName assemblyName = null;
            try
            {
                assemblyName = AssemblyName.GetAssemblyName(FileName);
                return assemblyName.Load();
            }
            catch (Exception)
            {
                return null;
            }
        }
Michael
Sep 27, 2013 at 1:10 PM
The solution above is tested and working.
Michael
Sep 27, 2013 at 3:34 PM
Switched the code a bit, but thank you for letting me know about the issue. It has been a while since I've dealt with COM objects in a project so I didn't think to check that. Anyway, new version has been uploaded to NuGet.
Sep 27, 2013 at 4:09 PM
As always: Lightning Fast!

Works like a charm!

Thanks a lot,
Michael