title: How to determine whether a DLL is a managed assembly or native (prevent loading a native dll)?
body: <h2>Original title: How can I prevent loading a native dll from a .NET app?</h2>
  
  <p><strong>Background:</strong></p>
  
  <p>My C# application includes a plugin framework and generic plugin loader.</p>
  
  <p>The plugin loader enumerates the application directory in order to identify plugin dlls (essentially it searches for *.dll at this time). </p>
  
  <p>Within the same application directory is a native (Windows, non-.net) dll, which, indirectly, one of the plugin dlls depends upon.</p>
  
  <p>The plugin loader blindly assumes that the native.dll is a .NET Assembly dll, simply because it only checks the file extension. When it attempts to load the native dll, an exception is thrown:</p>
  
  <p>"Could not load file or assembly 'native.dll' or one of its dependencies. The module was expected to contain an assembly manifest."</p>
  
  <p>I basically create a diagnostic report if plugin loading fails, so I'm trying to avoid having this log filled up with messages about not being able to load the native dll (which I don't even want to attempt).</p>
  
  <p><strong>The question:</strong></p>
  
  <p>Is there some .NET API call that I can use to determine whether a binary happens to be a .NET assembly so that I don't attempt to load the native dll at all?</p>
  
  <p>Perhaps longer term I will move my plugins to a subdirectory, but for now, I just want a work around that doesn't involve hard-coding the "native.dll" name inside my plugin loader. </p>
  
  <p>I guess I'm looking for some kind of static Assembly.IsManaged() API call that I've overlooked.... presumably no such API exists?</p>