Question

This is my App.config

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <startup> 
        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
    </startup>
    <runtime>
      <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
        <probing privatePath="lib" />
      </assemblyBinding>
    </runtime>
</configuration>

My referenced DLLs are set to not copy to local and I've copied the DLLs to the lib directory in the debug folder and it works well, but when I move my program along with my library folder it doesn't work.

Is there a way I could make it work when the program and library directory to a different folder?

No correct solution

OTHER TIPS

A bit late to this one, but there is an alternative, add this to your Main method

AppDomain.CurrentDomain.AssemblyResolve += CurrentDomainAssemblyResolve;

The create the method

    private static Assembly CurrentDomainAssemblyResolve(object sender, ResolveEventArgs args)
    {
        AssemblyName assyName = new AssemblyName(args.Name);
        string filename = args.Name.ToLower().Split(',')[0];
        string path = "c:\some path or other\"
        string assembly = System.IO.Path.Combine(path, filename);

        if (!assembly.EndsWith(".dll"))
            assembly += ".dll";

        try
        {
            if (System.IO.File.Exists(assembly))
                return (Assembly.LoadFrom(assembly));
        }
        catch (Exception error)
        {
            // do whatever
        }

        return (null);
    }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top