c# - Scanning DLLs for .NET assemblies with a particular interface - some DLLs throw R6034! -


i have program needs discover plugin dlls on host.

it enumerating dlls within (fairly large) path. path includes lots of things, including native 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 scanner hits ms runtime dll (for example, msvcm80.dll) uncatchable runtime error r6034: "an application has made attempt load c runtime library incorrectly." window blocks execution of program. don't want dll (obviously); there way graceful error out of situation?

[related q: there efficient (e.g. non-exception) way of determining if dll .net assembly or not, if dll not loaded process space?]

first reflection-only load assembly.reflectiononlyloadfrom. after find plugin in assembly should load assembly.loadfrom.

to answer other question, can check whether file has clr header.

see post "read clr header" on m.p.dotnet.framework

together these should let avoid exceptions , error messageboxes while searching plugins.


Comments

Popular posts from this blog

apache - Add omitted ? to URLs -

redirect - bbPress Forum - rewrite to wwww.mysite prohibits login -

php - How can I stop spam on my custom forum/blog? -