NullReferenceException at Telerik.Windows.Controls.SyntaxEditor.UI.IntelliPromptBase.SetPosition

1 Answer 16 Views
SyntaxEditor
Schoetbi
Top achievements
Rank 1
Schoetbi asked on 09 Oct 2025, 02:33 PM | edited on 09 Oct 2025, 03:05 PM

I use the SyntaxEditor (v2024.4.1113.48, but also checked 2025.3.813.462) in WPF and want to show a completion list. As soon as I call

completionWindow.Show();

the completion window is shown for a very short amount of time in the upper left corner of the screen (not at the carret position). And after approx 200ms the exception occurs.

The function is

private void ShowCompletionWindow(RadSyntaxEditor codeEditor, string[] candidates)
 {
     try
     {
         var completionWindow = codeEditor.IntelliPrompts.CompletionListWindow;
         if (completionWindow?.Presenter == null)
         {
             return;
         }

         var completionList = new CompletionInfoCollection();
         foreach (var candidate in candidates)
         {
             completionList.Add(new CompletionInfo(candidate));
         }

         completionWindow.Presenter.CompletionListItems = completionList;

         // Validate caret position once more before showing
         if (codeEditor.CaretPosition.LineNumber >= 0 && codeEditor.CaretPosition.LineNumber < codeEditor.Document.CurrentSnapshot.LineCount)
         {
             completionWindow.Show();
         }
     }
     catch (Exception innerEx)
     {
         _log.Error("Exception showing completion window", innerEx);
     }
 }

This function gets called from TextDocument.TextContentChanged event handler. This might be the reason. I want to type and want to show identifieres, that start with the string that the user started typing.

The exception

 at Telerik.Windows.Controls.SyntaxEditor.UI.IntelliPromptBase.SetPosition(Point pointInScreen)
   at Telerik.Windows.Controls.SyntaxEditor.UI.IntelliPromptBase.SetPosition(Point pointInEditorPresenter, Point pointAboveTheCaret)
   at Telerik.Windows.Controls.SyntaxEditor.UI.IntelliPromptBase.SetPositionInView()
   at System.EventHandler.Invoke(Object sender, EventArgs e)
   at Telerik.Windows.Controls.SyntaxEditor.Layout.SyntaxEditorLayout.OnArrangeExecuted()
   at Telerik.Windows.Controls.SyntaxEditor.Layout.SyntaxEditorLayout.Arrange()
   at Telerik.Windows.Controls.SyntaxEditor.UI.SyntaxEditorPresenter.ArrangeOverride(Size arrangeBounds)
   at System.Windows.FrameworkElement.ArrangeCore(Rect finalRect)
   at System.Windows.UIElement.Arrange(Rect finalRect)
   at System.Windows.ContextLayoutManager.UpdateLayout()
   at System.Windows.ContextLayoutManager.UpdateLayoutCallback(Object arg)
   at System.Windows.Media.MediaContext.FireInvokeOnRenderCallbacks()
   at System.Windows.Media.MediaContext.RenderMessageHandlerCore(Object resizedCompositionTarget)
   at System.Windows.Media.MediaContext.RenderMessageHandler(Object resizedCompositionTarget)
   at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
   at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)

1 Answer, 1 is accepted

Sort by
0
Martin Ivanov
Telerik team
answered on 10 Oct 2025, 03:53 PM

Hello Tobias,

I've collected the extra information from the associated internal ticket on this topic and will answer also here in order to help anyone who stumbles on the same problem.

For context: it turned out that the RadSyntaxEditor is hosted in a WinForms application.

The exception is thrown because of the following line in the internal source code of the control:

  Matrix transformToDevice = PresentationSource.FromVisual((Visual)Application.Current.MainWindow).CompositionTarget.TransformToDevice;

The Application.Current is null because in the scenario where a WPF control is hosted in a WinForms application there is no application initialized. To make sure this works you will need to initialize both a WPF application and also assign and show its MainWindow. You can use the following hack to resolve the problem:

 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);
 }

This initialized the application and creates a hidden window.

In any case, this can be considered a bug in the positioning logic of the IntelliPrompts, so I've logged it in our feedback portal. I also updated your Telerik points.

Regards,
Martin Ivanov
Progress Telerik

Your perspective matters! Join other professionals in the State of Designer-Developer Collaboration 2025: Workflows, Trends and AI survey to share how AI and new workflows are impacting collaboration, and be among the first to see the key findings.
Start the 2025 Survey
Tags
SyntaxEditor
Asked by
Schoetbi
Top achievements
Rank 1
Answers by
Martin Ivanov
Telerik team
Share this question
or