简体   繁体   中英

MEF plugin can't find referenced library

I'm implementing a plugin system with MEF and so far it's working great. I've recently run into a problem though: The main application uses a SQLite database and now I have a plugin that has to access that database as well. When I copy the plugin to my plugin directory mef picks it up correctly but as soon as it tries to access anything with SQlite I get a System.IO exception telling me that it can't find the sqlite dll it depends on.

I tried copying the sqlite dlls to the plugin directory as well but it still won't work. Shouldn't any libraries I referenced in my main application also be available in my plugin? And even if not, shouldn't the plugin find the libraries if they're in the same directory?

Any help would be appreciated.

The SQLite assembly should be in your path, or in your application's directory, not in your modules directory. If this is the case, and you still get the same error, then it sounds like the exact same problem I posted here , with the following solution:

public static class AssemblyResolverFix
{
  //Looks up the assembly in the set of currently loaded assemblies,
  //and returns it if the name matches. Else returns null.
  public static Assembly HandleAssemblyResolve( object sender, ResolveEventArgs args )
  {
    foreach( var ass in AppDomain.CurrentDomain.GetAssemblies() )
      if( ass.FullName == args.Name )
        return ass;
    return null;
  }
}

//in main
AppDomain.CurrentDomain.AssemblyResolve += AssemblyResolverFix.HandleAssemblyResolve;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM