And it worked.
If you go look in the properties of the Samplepdfviewer you will notice that it is set to run for a .net 2.0 framework.
You might want to change that to .net 4.
If you try to run this now you will get this error.
An error occurred creating the form. See Exception.InnerException for details. The error is: Mixed mode assembly is built against version ‘v2.0.50727’ of the runtime and cannot be loaded in the 4.0 runtime without additional configuration information.
But that is easily fixed by adding the following line to your app.config.
<?xml version="1.0"?> <configuration> <startup useLegacyV2RuntimeActivationPolicy="true"> <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/> </startup> </configuration>
The part with
useLegacyV2RuntimeActivationPolicy=“true” is important since you might already have the other bits.
If you run it now it will just work.
Until you click on the browse button and select a file and click Ok. You will then get the following error.
Declaration referenced in a method implementation cannot be a final method. Type: ‘PDFLibNet.xPDFBinaryReader’. Assembly: ‘PDFLibNet, Version=22.214.171.124, Culture=neutral, PublicKeyToken=26d87f7d66fb2aee’.
Oh joy. This is also “easily” fixed. Just replace the PDFLibnet.dll in your output folder with the one in the PDFView/lib/net4.0/ and then pick the x86 or x64 depending on your system. You can not change the reference in you PDFView project since that expects a .Net 2.0 library. You could change the PDFView to .net 4.0 too and then change the reference but I didn’t not find that to be necessary.
And if you run it now and open your pdf you will see this.
And on your development machine there is a 99% chance that this will work. This will work because like 99% of developers you installed Visual studio with the default parameters. And this means that the VC++ libraries are also installed. You might want to note that your clients will probably not have these installed and it will therefor crash on you when you run it there. It will say that PDFLibNet.dll can not be loaded because it is missing or one of it’s dependencies is missing. And we all know PDFLibnet is there so it must be the dependencies.
Those dependencies are the VC++ 2010 libraries. You can easily download and install them.
And now your clients will have a working pdfviewer and you will have .net 4.0 code to play with, so everyone is happy.