4

I am developing a C# application in which the main application window has a 'tabbed' display, with each tab providing a different feature of the application.

I already have working tabs for a built in web browser, and a 'status' page that displays the status of the connection between the application and a remote server.

I am now trying to add another tab that will act as a 'document reader'.

Before I started trying to add this functionality inside another tab, I wrote a completely separate 'document reader' application, which is fully functioning. My intention is to now 'copy' the C# and XAML from this working standalone document reader into the source for my main application- adding the XAML markup to a 'new tab', and the C# code to the corresponding .xaml.cs file.

In my standalone document reader application, I was using the MoonPDF library to read the PDF documents, and that was working correctly.

However, after copying the XAML markup, and C# code behind into my existing application, I kept getting DLLNotFoundExceptions, even though I had copied all of the DLLs for the external library to the bin folder of my application.

I tried working through this for a while, but couldn't seem to get it working, so I have decided to revert my changes.

However, when I now try to run my original application, having reverted the changes, I get a XamlParseException which says:

Exception thrown: 'System.Windows.Markup.XamlParseException' in PresentationFramework.dll

Additional information: 'The invocation of the constructor on type 'Agent.MainWindow' that matches the specified binding constraints threw an exception.' Line number '5' and line position '5'.

When I 'View Detail' on the exception, and inspect the InnerException, it says:

{"Retrieving the COM class factory for component with CLSID {...} failed due to the following error: 8007007e The specified module could not be found. (Exception from HRESULT: 0x8007007e).":null}

I can't see the PresentationFramework.dll file anywhere in my folder structure- is that what the issue is here?

When I Google'd the error, I came across the following question on SO: Retrieving the COM class factory for component with CLSID {XXXX} failed due to the following error: 80040154

The accepted answer on that question suggests that I should check the project properties, that the platform target is set to 'x86'- I have checked, and it is. The other two most 'upvoted' answers suggest that I may be using a 32-bit process or DLL, and so need to build for 'x86'- I am aware that the MoonPDF library that I am using is 32-bit, and so am already compiling/ running my code for 'x86', rather than 'Any CPU'.

Are there any other reasons why I might be getting this runtime error? What else can I do to try and resolve it?

Community
  • 1
  • 1
Noble-Surfer
  • 3,052
  • 11
  • 73
  • 118

1 Answers1

1

Just add PresentationFramework.dll to your project where you've taken the exception. It can be done by five steps:

  1. Right Click of Mouse at the project in Solution Explorer.
  2. Select Add -> Reference. The Add Reference dialog box opens.
  3. Then Assemblies -> Framework.
  4. Choose PresentationFramework
  5. Click OK when you have selected you necessary library. Selected reference will appear under the References node of the project.

Update:

Change in Visual Studio project properties:

  1. Project properties
  2. In Build tab
  3. Platform target =X86
StepUp
  • 36,391
  • 15
  • 88
  • 148
  • Hey, thanks for your answer... I gave that a try, but `PresentationFramework` is already selected in the list of `Assemblies`, and is also already listed under the References node of the project... any other ideas/ suggestions? – Noble-Surfer Jun 01 '16 at 11:01
  • The error message says that the exception was thrown in the DLL, and also states: `Additional information: 'The invocation of the constructor on type 'Agent.MainWindow' that matches the specified binding constraints threw an exception.' Line number '5' and line position '5'.` The InnerException appears to be complaining about where I am creating an instance of the WebKitBrowser: `WebKit.WebKitBrowser browser = new WebKit.WebKitBrowser();`... but I can't see any issues with how I've declared that- and haven't changed it since the last time my code complied and ran successfully. – Noble-Surfer Jun 01 '16 at 11:05
  • Thanks for the update- again, this is something that I had already tried... The platform target is set to 'x86', and I am trying to build in Debug, using 'x86' rather than 'Any CPU', as I mentioned in my OP. – Noble-Surfer Jun 01 '16 at 11:15
  • @someone2088 try to run this code `WebKit.WebKitBrowser browser = new WebKit.WebKitBrowser();.` in `try catch` statemeny using debugger to find an exact place where we caught an error. – StepUp Jun 01 '16 at 12:21
  • Ok, I'll give that a go now. Out of interest- I tried removing the `PresentationFramework` as a reference, by 'unchecking' it in Project -> Add Reference, and then adding it back in again... When I removed it, my code showed up a lot of errors, and after adding it again, the errors have gone from the code, but the error list still shows one which says `Project file must include the .NET Framework assembly 'PresentationFramework' in the reference list.`. In the Solution Explorer, `PresentationFramework` is listed under `References` for my project... is that what this means? – Noble-Surfer Jun 01 '16 at 12:26
  • Actually, I can't run that in a `try-catch`, as I am declaring `browser` as a global variable... it's not local to any specific method... – Noble-Surfer Jun 01 '16 at 12:30
  • @someone2088 you can set breakpoint at this line `WebKit.WebKitBrowser browser = new WebKit.WebKitBrowser();.` or just declare as a **local to class** this variable and create this variable in the constructor. – StepUp Jun 01 '16 at 12:41
  • Unfortunately, I can't add a breakpoint to the line, as the exception is thrown as soon as I run the application... – Noble-Surfer Jun 01 '16 at 12:56
  • I'm just wondering if I should delete the files that are automatically generated when you build a project, in case the compiler hasn't overwritten these since I reverted my changes, and is still trying to use the auto-generated files that were compiled for code that I'm no longer trying to run? – Noble-Surfer Jun 01 '16 at 12:59
  • @someone2088 just set a breakpoint at start of your program to find a place where you program breaks. – StepUp Jun 01 '16 at 13:04
  • The problem is, I can't set a breakpoint at all, as you can't set breakpoints while the code is not running (I have tried clicking on the line numbers for the first line of my application: `public partial class MainWindow : Window{`, but nothing happens, and the exception is thrown as soon as I start running it- the application is not even initialised... – Noble-Surfer Jun 01 '16 at 13:11
  • It might help to say that when viewing the XAML for my application, the 'preview' panel is displaying the application correctly- as it was displayed when the app was last running successfully, so I definitely wouldn't have thought that there are any compile issues, or else the 'preview' would not be displayed at all... but I haven't changed anything that would cause a runtime exception since the last time I had it running- the code (both C# and XAML) is identical to what it was the last time my application was running successfully... – Noble-Surfer Jun 01 '16 at 14:05
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/113539/discussion-between-stepup-and-someone2088). – StepUp Jun 01 '16 at 14:07