Unplanned
Last Updated: 10 Oct 2025 15:44 by Martin Ivanov
Martin Ivanov
Created on: 10 Oct 2025 15:44
Category: SyntaxEditor
Type: Bug Report
0
SyntaxEditor: NullReferenceException thrown on opening the CompletionListWindow when RadSyntaxEditor is hosted in a non-WPF application and there is no WPF Application and MainWindow initialized

NullReferenceException thrown on opening the CompletionListWindow when RadSyntaxEditor is hosted in a non-WPF application (usually WinForms) and there are no WPF Application and MainWindow initialized. 

This can happen if the RadSyntaxEditor for WPF is hosted in a WinForms application. In this scenario the System.Windows.Application.Current and its MainWindow are not initialized, which is what the IntelliPrompt positioning logic relies on.

Exception details:

System.NullReferenceException: 'Object reference not set to an instance of an object.'
> Telerik.Windows.Controls.SyntaxEditor.dll!Telerik.Windows.Controls.SyntaxEditor.UI.IntelliPromptBase.SetPosition(System.Windows.Point pointInScreen) Line 452 C#  Telerik.Windows.Controls.SyntaxEditor.dll!Telerik.Windows.Controls.SyntaxEditor.UI.IntelliPromptBase.SetPosition(System.Windows.Point pointInEditorPresenter, System.Windows.Point pointAboveTheCaret) Line 442 C#  Telerik.Windows.Controls.SyntaxEditor.dll!Telerik.Windows.Controls.SyntaxEditor.UI.IntelliPromptBase.SetPositionInView() Line 480 C#  Telerik.Windows.Controls.SyntaxEditor.dll!Telerik.Windows.Controls.SyntaxEditor.UI.IntelliPromptBase.InitializeIntellisense() Line 401 C#  Telerik.Windows.Controls.SyntaxEditor.dll!Telerik.Windows.Controls.SyntaxEditor.UI.IntelliPromptBase.Show(Telerik.Windows.Controls.SyntaxEditor.UI.CaretPosition caretStartPosition, Telerik.Windows.Controls.SyntaxEditor.UI.CaretPosition caretEndPositions) Line 211 C#
  Telerik.Windows.Controls.SyntaxEditor.dll!Telerik.Windows.Controls.SyntaxEditor.UI.IntelliPromptBase.Show() Line 182 C#

To work this around, you can initialize a new WPF application and MainWindow and create a hidden HwndSource for the MainWindow. This should happen before showing the WPF content in the WinForms application's code. 

 public Form1()
 {
     InitializeComponent();

     new System.Windows.Application();
     System.Windows.Application.Current.MainWindow = new System.Windows.Window();

     var parameters = new HwndSourceParameters("HiddenHost")
     {
         Width = 1, Height = 1,
         WindowStyle = unchecked((int)0x80000000) // WS_POPUP | WS_EX_NOACTIVATE
     };
     var hwndSource = new HwndSource(parameters);
     hwndSource.RootVisual = System.Windows.Application.Current.MainWindow;

      // other code here

     ElementHost host = new ElementHost { Dock = DockStyle.Fill };
     host.Child = wpfControl
     this.Controls.Add(host);
 }

0 comments