Question

I have written a small shell extension, the stub works, but want it to read some info from an SQLite database.

SQLite needs 2 DLLs:

  • System.Data.SQLite.dll: managed-only core assembly
  • SQLite.Interop.dll: native interop assembly

In the past, I have successfully built desktop applications using these 2 DLLs, by putting them in the same folder as the .exe file.
But in the case of a shell extension, there is no such thing as a .exe file, so where should I put these DLLs?

Note: Right now I deploy the shell extension with Regasm, but I plan to deploy them with WiX in the future.

Was it helpful?

Solution

As you likely already know, assemblies are found relative to the .exe and the instructions in its .exe.config file. That means your .dll will have to take care of loading its assemblies "by hand".

AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(ResolveLocally);

static Assembly ResolveLocally(object sender, ResolveEventArgs args)
{
    string path = Path.Combine(
        Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location),
        new AssemblyName(args.Name).Name + ".dll"
        );
    if (!File.Exists(path))
    {
       return null;
    }

    return Assembly.LoadFrom(path);
}

This is basically the same as here: How to add folder to assembly search path at runtime in .NET?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top