I have a program that should detect plugin DLL modules on its host.
He does this by listing all the DLLs in the path (quite large). This path includes many things, including your own DLLs.
foreach (var f in Directory.EnumerateFiles(@"c:\Program Files", "*.dll", SearchOption.AllDirectories)) { try { var assembly = Assembly.LoadFile(f); var types = assembly.GetTypes(); foreach (var type in types) { if (type.GetInterface("My.IInterface") != null) { plugins.Add(f); break; } } assembly = null; } catch (Exception e) { } }
If my scanner enters the MS runtime DLL (for example, msvcm80.dll), I get an unrecoverable R6034 runtime error: "The application tried to load the C runtime library incorrectly." This window blocks the execution of the program. I do not want this DLL (obviously); is there any way to get an elegant error from this situation?
[Related q: is there an efficient (for example, no exception) way to determine if a DLL is a .NET assembly or not if that DLL is not currently loading into the process space?]
Joe
source share