Error Hosting WindowsFormsHost in Caliburn micro app

Topics: Bootstrappers & IoC
Jan 28, 2014 at 10:23 PM
Edited Jan 28, 2014 at 10:37 PM
Help needed.

{"The invocation of the constructor on type 'Planviewer.Utils.PDFViewerHost' that matches the specified binding constraints threw an exception."}

Here is the XAML

<utils:PDFViewerHost x:Name="PDFViewer" PDFPath="{Binding CurrentPDFFile}" MakeDirty="{Binding IsDirty}" Margin="0" />

Here is the class
 public class PDFViewerHost : WindowsFormsHost
 {
    public static readonly DependencyProperty PDFPathProperty = DependencyProperty.Register(
        "PDFPath", typeof(string), typeof(PDFViewerHost), new PropertyMetadata(PDFPathPropertyChanged));

    public static readonly DependencyProperty MakeDirtyProperty = DependencyProperty.Register(
        "MakeDirty", typeof(bool), typeof(PDFViewerHost), new PropertyMetadata(MakeDirtyPropertyChanged));

    private readonly PDFViewer wrappedControl;

    public PDFViewerHost()
    {
        wrappedControl = new PDFViewer();
        Child = wrappedControl;
    }

    public string PDFPath
    {
        get { return (string)GetValue(PDFPathProperty); }
        set
        {
            SetValue(PDFPathProperty, value);
        }
    }

    public bool MakeDirty
    {
        get { return (bool)GetValue(MakeDirtyProperty); }
        set
        {
            SetValue(MakeDirtyProperty, value);
        }
    }

    private static void PDFPathPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
    {
        PDFViewerHost host = (PDFViewerHost)d;
        host.wrappedControl.PDFFilePath = (string)e.NewValue;
    }

    private static void MakeDirtyPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
    {
        PDFViewerHost host = (PDFViewerHost)d;
        host.wrappedControl.MakeDirty = true;
    }
}
Jan 29, 2014 at 11:16 AM
Could you check if the exception InnerException property holds useful information?
Jan 29, 2014 at 1:54 PM
The inner exception says the following "{'Class not registered (Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREF))'}"

If I run the app in Debug mode everything works fine but when I select Release it shows this error.
Jan 29, 2014 at 2:02 PM
It seems the problem lies in the PDFViewer component (it should be a COM exception).
Are you sure the target platform is the same in Debug and Release? I have checked for a similar error when dealing with a PdfViewer (or alike) class, and I found this article, stating that using the approach described in the article works only if the platform is x86, since the pdf viewer component cannot work in x64 (which is equivalent to AnyCPU on an x64 system).
Jan 29, 2014 at 6:28 PM
That did the trick.

Thanks