1

I've added as reference PDFSharp classes for a project. When I tried to use a method in a class that includes PDFSharp libraries I get a FileNotFoundException that states I'm missing the referenced (PDFSharp) file (while I can assure you the dll file is there).

So I've tried adding and readding and changing the dll version, but still without success. So I switched to PDFClown, a similar purpose library, but the error is the same: FileNotFoundException at runtime.

The exception is thrown even before the method is executed.

Calling method (where the exception is thrown):

//method call: here the debugger stops at the breakpoint
ReportUtils.CreateFile(tempDirectoryPath ecc);

Called method:

using org.pdfclown.documents;
using org.pdfclown.documents.contents.composition;
using org.pdfclown.documents.contents.fonts;
using clownFiles = org.pdfclown.files;

class ReportUtils
{
    public static void CreateFile(/*parameters*/)
    {
             //the debugger never enter here: the exception is thrown before
             string filename = Settings.ReportFileName + String.Format("{0:yyyyMMddHHmmssffff}", DateTime.Now);
             //ecc
    }
//...

Why is this exception showing up? Am I doing something wrong adding the references?

Gorgsenegger
  • 7,356
  • 4
  • 51
  • 89
misleadingTitle
  • 657
  • 6
  • 21
  • 1
    Do you have COPIED the referenced DLL in the execution folder? (BIN\DEBUG) – Steve Sep 19 '13 at 10:44
  • are you running your application in debug mode or released mode ? – Ronak Patel Sep 19 '13 at 10:46
  • I'm running in debug. I've referenced it using the 'Add Reference' button and copied them in a 'lib' folder. – misleadingTitle Sep 19 '13 at 10:49
  • @misleadingTitle define "in a lib folder": unless you have "probing paths" configured, they need to end up in the same folder as the exe that gets executed – Marc Gravell Sep 19 '13 at 10:50
  • FileNotFoundException should be providing you the file path where it is looking for the file. please share with us – Ronak Patel Sep 19 '13 at 10:55
  • Ok, you almost got it right. The problem is that the dll is not in the exe folder. The problem is that here I'm developing a plugin-dll used by another project. So even if I set "copy local", visual studio copy my pdf library where my plugin-dll output is, but not in the main exe folder. So, is there a way to also copy the "dependencies" of a dll in the main exe folder? I hope my problem is clear. Also, how can I post an "update" to my question to maximize visibility? Should I edit it? – misleadingTitle Sep 19 '13 at 11:58
  • @misleadingTitle Another thing you could do is add a build step to merge the two assemblies into one using [ILMerge](https://www.microsoft.com/en-us/download/details.aspx?displaylang=en&id=17630). That should make using it in dependent projects easier, although it will complicate your build. You'll probably have to add a custom post-build step to do that and delete the local copy of the PDFSharp/PDFClown DLL after building your plugin. – millimoose Sep 19 '13 at 12:04

1 Answers1

1

I could reproduce your issue by setting the option Copy Local on my library to false. Please, make sure this boolean is set to true..

enter image description here

Jämes
  • 6,945
  • 4
  • 40
  • 56