Hi,
we use Telerik V2012.1.326.35 with VS2008 and we have a strange problem :(
Actually in our solution, in one of our project we added a RadPdfViewer in a XAML file. In code behind, on a RadButton click event, we call the following method :
private void loadDoc()
{
PdfDocumentSource newDoc = new PdfDocumentSource(new Uri(@"c:\MyDir\pdf2.pdf"));
PdfDoc.DocumentSource = newDoc;
}
I don't know why but I always received the follwing error message (see attached file).
If I move our method in a brand new solution and project, it work!!! I checked all Telerik files and they are the same in both projects.
Any thought???
Thank's
7 Answers, 1 is accepted
Did you looked at the "View Detail" for details about this exception? Sometimes this reveals more info and can be useful. If there is a stack trace with telerik components involved, please copy it and send it to us.
Other than that the only thing that comes to mind is something in the assembly references or the project settings.
If you have added all required assembly references as listed here and the project settings in the two applications are the same, please open a support ticket and attach the project illustrating the issue, so that we can test it on our end and determine the cause of the incorrect behavior.
Iva Toteva
the Telerik team
Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.
System.NullReferenceException was unhandled
Message="La référence d'objet n'est pas définie à une instance d'un objet."
Source="Telerik.Windows.Controls.FixedDocumentViewers"
StackTrace:
à Telerik.Windows.Documents.Fixed.FixedDocumentStreamSource.<>c__DisplayClass8.<LoadDocument>b__6() dans c:\TB\105\WPF_Scrum\Release_WPF\Sources\Development\Documents\Fixed\FixedDocumentViewers\Fixed\FixedDocumentStreamSource.cs:ligne 118
à System.Threading.ThreadHelper.ThreadStart_Context(Object state)
à System.Threading.ExecutionContext.runTryCode(Object userData)
à System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode code, CleanupCode backoutCode, Object userData)
à System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
à System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
à System.Threading.ThreadHelper.ThreadStart()
InnerException:
Thank's
Unfortunately, we are still not able to track the cause of the issue from the information you have provided.
Please, open a support ticket and attach your project, so that we can assist you further.
Iva Toteva
the Telerik team
Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.
I do not know if it's the same problem but do notice that when using the pdfViewer from within a wpf project everything works fine.
But when I use a ElementHost to host the pdfViewer I can not load any pdf document.
Even using the UI of the component generates a crash. I think it's something to do with threads / dispatcher.
Error
{"Object reference not set to an instance of an object."}
" at Telerik.Windows.Documents.Fixed.FormatProviders.Pdf.Utils.Helper.get_Dispatcher() in c:\TB\102\WPF_Scrum\Release_WPF\Sources\Development\Documents\Fixed\Core\FormatProviders\Pdf\Utils\Helper.cs:line 147".
I have used the latest trial , and in production we have version 2011.3.1205.40. And also there I encounter the problem.
The Code
public partial class Form1 : Form
{
private readonly RadPdfViewer _pdfViewer;
private readonly WpfWrapper _pdfWpfWrapper;
public Form1()
{
InitializeComponent();
_pdfViewer = new RadPdfViewer { Name = "_pdfViewer" };
var document = new PdfDocumentSource(new Uri("c:\\1.pdf")).Document;
_pdfViewer.Document = document;
//var textBox = new TextBox();
_pdfWpfWrapper = new WpfWrapper(_pdfViewer)
{ BackColor = Color.FloralWhite,
Location = new Point(0, 0),
Width = this.Width - 10,
Name = @"_pdfWpfWrapper",
TabStop = true,
TabIndex = 0,
Text = @"_pdfWpfWrapper",
Dock = DockStyle.Fill
};
Controls.Add(_pdfWpfWrapper);
}
}
public class WpfWrapper : System.Windows.Forms.Integration.ElementHost
{
public static Dispatcher Dispatcher { get; private set; }
public WpfWrapper(FrameworkElement wrapped)
{
Location = new System.Drawing.Point(0, 0);
Name = "elementHost";
BackColorTransparent = true;
TabStop = false; //artf53800
Child = wrapped;
if (Dispatcher == null)
{
Dispatcher = Child.Dispatcher;
}
}
// Fix: Keyboard events are not transfered to the winforms host
[DllImport("user32.dll")]
public static extern int SendMessage(IntPtr hWnd, int msg, IntPtr wParam, IntPtr lParam);
protected override bool ProcessCmdKey(ref System.Windows.Forms.Message m, System.Windows.Forms.Keys keyData)
{
bool processed = base.ProcessCmdKey(ref m, keyData);
if (!processed)
{
SendMessage(Parent.Handle, m.Msg, m.WParam, m.LParam);
}
return processed;
}
}
There is one additional thing to do in order to make RadPdfViewer work in a WinForms application: you should ensure that the Application.Current property is initialized before the user control is initialized, for example by adding this code in the constructor of the user control:
public
PdfViewerControl()
{
if
(Application.Current ==
null
)
{
new
Application();
}
InitializeComponent();
}
I hope this helps.
Regards,
Kammen
the Telerik team
Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.
Yes this works perfectly !
Thanks.
__________________