Selkiss / lib-pdf

Automatically exported from code.google.com/p/lib-pdf
0 stars 0 forks source link

Not working... #4

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
I got when run project "Could not load file or assembly 'libpdf.dll' or one of 
its dependencies. The specified module could not be found."

But this dll I added to references.

Original issue reported on code.google.com by vitalyta...@gmail.com on 29 Mar 2012 at 11:57

GoogleCodeExporter commented 8 years ago
No matter what I do....
Could not load file or assembly 'libpdf.dll' or one of its dependencies. The 
specified module could not be found

Original comment by bill.bor...@gmail.com on 4 Jan 2013 at 8:15

GoogleCodeExporter commented 8 years ago
Same issue....

Original comment by csnv...@gmail.com on 16 May 2013 at 7:22

GoogleCodeExporter commented 8 years ago
Hi Folks,

Depending on how/where you're using this you *may* need to load the library 
manually. I've found this was necessary when using it in an ASP.NET project.  
Apparently it is a bit of a bug in how the .NET runtime handles mixed c++ dlls..

// Add this code somewhere BEFORE you use the libpdf code
// Adds a handler to the AssemblyResolve event to manually load the libpdf 
library when the CLR fails to find it
AppDomain.CurrentDomain.AssemblyResolve += new 
ResolveEventHandler(currentDomain_AssemblyResolve);

    // Put this function somewhere else in you're code.. Remember to change the 'Path to libPDF' bit below!!
    // Resolve assemblies the CLR can't find/load
    Assembly currentDomain_AssemblyResolve(object sender, ResolveEventArgs args)
    {
        if (args.Name.StartsWith("libpdf"))
        {
            string libPDFPath = <PATH to libPDF>

            if (File.Exists(libPDFPath))
            {
                try
                {
                    ProxyDomain pd = new ProxyDomain();
                    return pd.LoadAssembly(libPDFPath);
                }
                catch (Exception ex)
                {
                    throw new Exception("Could not load libPDF: " + libPDFPath, ex);
                }
            }
            else throw new FileNotFoundException("Could not find libPDF: " + libPDFPath);
        }
        else return null;
    }

HTH

Andrew

Original comment by a.bromw...@gmail.com on 31 May 2013 at 2:24

GoogleCodeExporter commented 8 years ago
Oops.. forgot definition of ProxyDomain class. Here it is (from 
http://stackoverflow.com/questions/658498/how-to-load-assembly-to-appdomain-with
-all-references-recursively):

using System;
using System.Reflection;

/// <summary>
/// Summary description for ProxyDomain
/// </summary>
public class ProxyDomain : MarshalByRefObject
{
    public Assembly LoadAssembly(string AssemblyPath)
    {
        try
        {
            return Assembly.LoadFrom(AssemblyPath);
        }
        catch (Exception ex)
        {
            throw new InvalidOperationException("Failed to load assembly", ex);
        }
    }
}

Original comment by a.bromw...@gmail.com on 31 May 2013 at 2:32

GoogleCodeExporter commented 8 years ago
This fix does not work, I still get the same error.
It appears that the zip file may be missing .dlls that are dependencies.

Original comment by worleb...@gmail.com on 17 Oct 2013 at 9:05

GoogleCodeExporter commented 8 years ago
bowlshit, spending time for nothing

Original comment by rafaelho...@gmail.com on 12 Jun 2015 at 4:43