Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CompletionWindow crash on show #357

Open
gusmanb opened this issue Jul 16, 2023 · 2 comments
Open

CompletionWindow crash on show #357

gusmanb opened this issue Jul 16, 2023 · 2 comments

Comments

@gusmanb
Copy link

gusmanb commented Jul 16, 2023

Version: Avalonia 11.0.0

When code completion window is shown AvaloniaEdit crashes with "System.InvalidCastException: 'Unable to cast object of type 'System.String' to type 'AvaloniaEdit.CodeCompletion.ICompletionData'.'"

Example:

    CompletionWindow? completionWindow;

    public class MyCompletionData : ICompletionData
    {
        public MyCompletionData(string text)
        {
            Text = text;
        }

        public IImage Image => null;

        public string Text { get; }

        // Use this property if you want to show a fancy UIElement in the list.
        public object Content => Text;

        public object Description => "Description for " + Text;

        public double Priority { get; } = 0;

        public void Complete(TextArea textArea, ISegment completionSegment,
            EventArgs insertionRequestEventArgs)
        {
            textArea.Document.Replace(completionSegment, Text);
        }
    }

    private void TextArea_TextEntered(object? sender, TextInputEventArgs e)
    {
        if (e.Text == ".")
        {
            // Open code completion after the user has pressed dot:
            completionWindow = new CompletionWindow(editor.TextArea);
            IList<ICompletionData> data = completionWindow.CompletionList.CompletionData;
            data.Add(new MyCompletionData("Item1"));
            data.Add(new MyCompletionData("Item2"));
            data.Add(new MyCompletionData("Item3"));
            completionWindow.Show();
            completionWindow.Closed += delegate {
                completionWindow = null;
            };
        }
    }

Stack Trace:

AvaloniaEdit.dll!CompiledAvaloniaXaml.XamlIlHelpers.AvaloniaEdit.CodeCompletion.ICompletionData,AvaloniaEdit.Content!Getter(object value)	Desconocido
Avalonia.Base.dll!Avalonia.Data.Core.ClrPropertyInfo.Get(object target) Línea 27	C#
Avalonia.Markup.Xaml.dll!Avalonia.Markup.Xaml.MarkupExtensions.CompiledBindings.InpcPropertyAccessor.Value.get() Línea 88	C#
Avalonia.Markup.Xaml.dll!Avalonia.Markup.Xaml.MarkupExtensions.CompiledBindings.InpcPropertyAccessor.SendCurrentValue() Línea 132	C#
Avalonia.Markup.Xaml.dll!Avalonia.Markup.Xaml.MarkupExtensions.CompiledBindings.InpcPropertyAccessor.SubscribeCore() Línea 117	C#
Avalonia.Base.dll!Avalonia.Data.Core.PropertyAccessorNode.StartListeningCore(System.WeakReference<object> reference) Línea 83	C#
Avalonia.Base.dll!Avalonia.Data.Core.ExpressionNode.StartListening() Línea 152	C#
Avalonia.Base.dll!Avalonia.Data.Core.ExpressionNode.Target.set(System.WeakReference<object> value) Línea 46	C#
Avalonia.Markup.dll!Avalonia.Data.BindingBase.UpdateSignal.PropertyChanged(object sender, Avalonia.AvaloniaPropertyChangedEventArgs e) Línea 281	C#
Avalonia.Base.dll!Avalonia.AvaloniaObject.RaisePropertyChanged<object>(Avalonia.AvaloniaProperty<object> property, Avalonia.Data.Optional<object> oldValue, Avalonia.Data.BindingValue<object> newValue, Avalonia.Data.BindingPriority priority, bool isEffectiveValue) Línea 706	C#
Avalonia.Base.dll!Avalonia.PropertyStore.EffectiveValue<object>.SetAndRaiseCore(Avalonia.PropertyStore.ValueStore owner, Avalonia.StyledProperty<object> property, object value, Avalonia.Data.BindingPriority priority, bool isOverriddenCurrentValue, bool isCoercedDefaultValue) Línea 236	C#
Avalonia.Base.dll!Avalonia.PropertyStore.ValueStore.SetLocalValue<object>(Avalonia.StyledProperty<object> property, object value) Línea 228	C#
Avalonia.Base.dll!Avalonia.PropertyStore.ValueStore.SetValue<object>(Avalonia.StyledProperty<object> property, object value, Avalonia.Data.BindingPriority priority) Línea 197	C#
Avalonia.Controls.dll!Avalonia.Controls.Presenters.ContentPresenter.UpdateChild(object content) Línea 462	C#
Avalonia.Base.dll!Avalonia.Layout.Layoutable.MeasureCore(Avalonia.Size availableSize) Línea 541	C#
Avalonia.Base.dll!Avalonia.Layout.Layoutable.Measure(Avalonia.Size availableSize) Línea 373	C#
Avalonia.Controls.dll!Avalonia.Controls.StackPanel.MeasureOverride(Avalonia.Size availableSize) Línea 273	C#
Avalonia.Base.dll!Avalonia.Layout.Layoutable.MeasureCore(Avalonia.Size availableSize) Línea 541	C#
Avalonia.Base.dll!Avalonia.Layout.Layoutable.Measure(Avalonia.Size availableSize) Línea 373	C#
Avalonia.Base.dll!Avalonia.Layout.LayoutHelper.MeasureChild(Avalonia.Layout.Layoutable control, Avalonia.Size availableSize, Avalonia.Thickness padding, Avalonia.Thickness borderThickness) Línea 48	C#
Avalonia.Controls.dll!Avalonia.Controls.Presenters.ContentPresenter.MeasureOverride(Avalonia.Size availableSize) Línea 583	C#
Avalonia.Base.dll!Avalonia.Layout.Layoutable.MeasureCore(Avalonia.Size availableSize) Línea 541	C#
Avalonia.Base.dll!Avalonia.Layout.Layoutable.Measure(Avalonia.Size availableSize) Línea 373	C#
Avalonia.Base.dll!Avalonia.Layout.Layoutable.MeasureOverride(Avalonia.Size availableSize) Línea 609	C#
Avalonia.Base.dll!Avalonia.Layout.Layoutable.MeasureCore(Avalonia.Size availableSize) Línea 541	C#
Avalonia.Base.dll!Avalonia.Layout.Layoutable.Measure(Avalonia.Size availableSize) Línea 373	C#
Avalonia.Controls.dll!Avalonia.Controls.VirtualizingStackPanel.RealizeElements(System.Collections.Generic.IReadOnlyList<object> items, Avalonia.Size availableSize, ref Avalonia.Controls.VirtualizingStackPanel.MeasureViewport viewport) Línea 538	C#
Avalonia.Controls.dll!Avalonia.Controls.VirtualizingStackPanel.MeasureOverride(Avalonia.Size availableSize) Línea 178	C#
Avalonia.Base.dll!Avalonia.Layout.Layoutable.MeasureCore(Avalonia.Size availableSize) Línea 541	C#
Avalonia.Base.dll!Avalonia.Layout.Layoutable.Measure(Avalonia.Size availableSize) Línea 373	C#
Avalonia.Base.dll!Avalonia.Layout.Layoutable.MeasureOverride(Avalonia.Size availableSize) Línea 609	C#
Avalonia.Base.dll!Avalonia.Layout.Layoutable.MeasureCore(Avalonia.Size availableSize) Línea 541	C#
Avalonia.Base.dll!Avalonia.Layout.Layoutable.Measure(Avalonia.Size availableSize) Línea 373	C#
Avalonia.Controls.dll!Avalonia.Controls.Presenters.ScrollContentPresenter.MeasureOverride(Avalonia.Size availableSize) Línea 384	C#
Avalonia.Base.dll!Avalonia.Layout.Layoutable.MeasureCore(Avalonia.Size availableSize) Línea 541	C#
Avalonia.Base.dll!Avalonia.Layout.Layoutable.Measure(Avalonia.Size availableSize) Línea 373	C#
Avalonia.Controls.dll!Avalonia.Controls.Grid.MeasureCell(int cell, bool forceInfinityV) Línea 1139	C#
Avalonia.Controls.dll!Avalonia.Controls.Grid.MeasureCellsGroup(int cellsHead, Avalonia.Size referenceSize, bool ignoreDesiredSizeU, bool forceInfinityV, out bool hasDesiredSizeUChanged) Línea 999	C#
Avalonia.Controls.dll!Avalonia.Controls.Grid.MeasureCellsGroup(int cellsHead, Avalonia.Size referenceSize, bool ignoreDesiredSizeU, bool forceInfinityV) Línea 961	C#
Avalonia.Controls.dll!Avalonia.Controls.Grid.MeasureOverride(Avalonia.Size constraint) Línea 491	C#
Avalonia.Base.dll!Avalonia.Layout.Layoutable.MeasureCore(Avalonia.Size availableSize) Línea 541	C#
Avalonia.Base.dll!Avalonia.Layout.Layoutable.Measure(Avalonia.Size availableSize) Línea 373	C#
Avalonia.Base.dll!Avalonia.Layout.Layoutable.MeasureOverride(Avalonia.Size availableSize) Línea 609	C#
Avalonia.Base.dll!Avalonia.Layout.Layoutable.MeasureCore(Avalonia.Size availableSize) Línea 541	C#
Avalonia.Base.dll!Avalonia.Layout.Layoutable.Measure(Avalonia.Size availableSize) Línea 373	C#
Avalonia.Base.dll!Avalonia.Layout.LayoutHelper.MeasureChild(Avalonia.Layout.Layoutable control, Avalonia.Size availableSize, Avalonia.Thickness padding, Avalonia.Thickness borderThickness) Línea 48	C#
Avalonia.Controls.dll!Avalonia.Controls.Border.MeasureOverride(Avalonia.Size availableSize) Línea 183	C#
Avalonia.Base.dll!Avalonia.Layout.Layoutable.MeasureCore(Avalonia.Size availableSize) Línea 541	C#
Avalonia.Base.dll!Avalonia.Layout.Layoutable.Measure(Avalonia.Size availableSize) Línea 373	C#
Avalonia.Base.dll!Avalonia.Layout.Layoutable.MeasureOverride(Avalonia.Size availableSize) Línea 609	C#
Avalonia.Base.dll!Avalonia.Layout.Layoutable.MeasureCore(Avalonia.Size availableSize) Línea 541	C#
Avalonia.Base.dll!Avalonia.Layout.Layoutable.Measure(Avalonia.Size availableSize) Línea 373	C#
Avalonia.Base.dll!Avalonia.Layout.Layoutable.MeasureOverride(Avalonia.Size availableSize) Línea 609	C#
Avalonia.Base.dll!Avalonia.Layout.Layoutable.MeasureCore(Avalonia.Size availableSize) Línea 541	C#
Avalonia.Base.dll!Avalonia.Layout.Layoutable.Measure(Avalonia.Size availableSize) Línea 373	C#
Avalonia.Base.dll!Avalonia.Layout.LayoutHelper.MeasureChild(Avalonia.Layout.Layoutable control, Avalonia.Size availableSize, Avalonia.Thickness padding, Avalonia.Thickness borderThickness) Línea 48	C#
Avalonia.Controls.dll!Avalonia.Controls.Presenters.ContentPresenter.MeasureOverride(Avalonia.Size availableSize) Línea 583	C#
Avalonia.Base.dll!Avalonia.Layout.Layoutable.MeasureCore(Avalonia.Size availableSize) Línea 541	C#
Avalonia.Base.dll!Avalonia.Layout.Layoutable.Measure(Avalonia.Size availableSize) Línea 373	C#
Avalonia.Base.dll!Avalonia.Layout.LayoutHelper.MeasureChild(Avalonia.Layout.Layoutable control, Avalonia.Size availableSize, Avalonia.Thickness padding) Línea 64	C#
Avalonia.Controls.dll!Avalonia.Controls.Decorator.MeasureOverride(Avalonia.Size availableSize) Línea 54	C#
Avalonia.Controls.dll!Avalonia.Controls.Primitives.VisualLayerManager.MeasureOverride(Avalonia.Size availableSize) Línea 139	C#
Avalonia.Base.dll!Avalonia.Layout.Layoutable.MeasureCore(Avalonia.Size availableSize) Línea 541	C#
Avalonia.Base.dll!Avalonia.Layout.Layoutable.Measure(Avalonia.Size availableSize) Línea 373	C#
Avalonia.Base.dll!Avalonia.Layout.Layoutable.MeasureOverride(Avalonia.Size availableSize) Línea 609	C#
Avalonia.Base.dll!Avalonia.Layout.Layoutable.MeasureCore(Avalonia.Size availableSize) Línea 541	C#
Avalonia.Base.dll!Avalonia.Layout.Layoutable.Measure(Avalonia.Size availableSize) Línea 373	C#
Avalonia.Base.dll!Avalonia.Layout.LayoutHelper.MeasureChild(Avalonia.Layout.Layoutable control, Avalonia.Size availableSize, Avalonia.Thickness padding) Línea 64	C#
Avalonia.Controls.dll!Avalonia.Controls.Decorator.MeasureOverride(Avalonia.Size availableSize) Línea 54	C#
Avalonia.Controls.dll!Avalonia.Controls.LayoutTransformControl.MeasureOverride(Avalonia.Size availableSize) Línea 121	C#
Avalonia.Base.dll!Avalonia.Layout.Layoutable.MeasureCore(Avalonia.Size availableSize) Línea 541	C#
Avalonia.Base.dll!Avalonia.Layout.Layoutable.Measure(Avalonia.Size availableSize) Línea 373	C#
Avalonia.Base.dll!Avalonia.Layout.Layoutable.MeasureOverride(Avalonia.Size availableSize) Línea 609	C#
Avalonia.Controls.dll!Avalonia.Controls.Primitives.PopupRoot.MeasureOverride(Avalonia.Size availableSize) Línea 133	C#
Avalonia.Controls.dll!Avalonia.Controls.WindowBase.MeasureCore(Avalonia.Size availableSize) Línea 274	C#
Avalonia.Base.dll!Avalonia.Layout.Layoutable.Measure(Avalonia.Size availableSize) Línea 373	C#
Avalonia.Base.dll!Avalonia.Layout.LayoutManager.Measure(Avalonia.Layout.Layoutable control) Línea 304	C#
Avalonia.Base.dll!Avalonia.Layout.LayoutManager.ExecuteInitialLayoutPass() Línea 192	C#
Avalonia.Controls.dll!Avalonia.Controls.WindowBase.Show() Línea 172	C#
Avalonia.Controls.dll!Avalonia.Controls.Primitives.Popup.Open() Línea 492	C#
AvaloniaEdit.dll!AvaloniaEdit.CodeCompletion.CompletionWindowBase.Show()	Desconocido
ZXBasicStudio.dll!ZXBasicStudio.DocumentEditors.ZXTextEditor.Controls.ZXTextEditor.TextArea_TextEntered(object sender, Avalonia.Input.TextInputEventArgs e) Línea 234	C#
AvaloniaEdit.dll!AvaloniaEdit.Editing.TextArea.OnTextEntered(Avalonia.Input.TextInputEventArgs e)	Desconocido
AvaloniaEdit.dll!AvaloniaEdit.Editing.TextArea.PerformTextInput(Avalonia.Input.TextInputEventArgs e)	Desconocido
AvaloniaEdit.dll!AvaloniaEdit.Editing.TextArea.OnTextInput(Avalonia.Input.TextInputEventArgs e)	Desconocido
Avalonia.Base.dll!Avalonia.Input.InputElement..cctor.AnonymousMethod__32_4(Avalonia.Input.InputElement x, Avalonia.Input.TextInputEventArgs e) Línea 220	C#
Avalonia.Base.dll!Avalonia.Reactive.LightweightObservableBase<(object, Avalonia.Interactivity.RoutedEventArgs)>.PublishNext((object, Avalonia.Interactivity.RoutedEventArgs) value) Línea 145	C#
Avalonia.Base.dll!Avalonia.Interactivity.EventRoute.RaiseEventImpl(Avalonia.Interactivity.RoutedEventArgs e) Línea 149	C#
Avalonia.Base.dll!Avalonia.Interactivity.EventRoute.RaiseEvent(Avalonia.Interactivity.Interactive source, Avalonia.Interactivity.RoutedEventArgs e) Línea 102	C#
Avalonia.Base.dll!Avalonia.Interactivity.Interactive.RaiseEvent(Avalonia.Interactivity.RoutedEventArgs e) Línea 125	C#
Avalonia.Base.dll!Avalonia.Input.KeyboardDevice.ProcessRawEvent(Avalonia.Input.Raw.RawInputEventArgs e) Línea 249	C#
Avalonia.Base.dll!Avalonia.Input.InputManager.ProcessInput(Avalonia.Input.Raw.RawInputEventArgs e) Línea 36	C#
Avalonia.Controls.dll!Avalonia.Controls.TopLevel.HandleInput(Avalonia.Input.Raw.RawInputEventArgs e) Línea 749	C#
Avalonia.Win32.dll!Avalonia.Win32.WindowImpl.AppWndProc(nint hWnd, uint msg, nint wParam, nint lParam) Línea 776	C#
Avalonia.Win32.dll!Avalonia.Win32.WindowImpl.WndProc(nint hWnd, uint msg, nint wParam, nint lParam) Línea 26	C#
[Transacción de nativo a administrado]	
[Transición de administrado a nativo]	
Avalonia.Win32.dll!Avalonia.Win32.Win32DispatcherImpl.RunLoop(System.Threading.CancellationToken cancellationToken) Línea 111	C#
Avalonia.Base.dll!Avalonia.Threading.DispatcherFrame.Run(Avalonia.Threading.IControlledDispatcherImpl impl) Línea 117	C#
Avalonia.Base.dll!Avalonia.Threading.Dispatcher.PushFrame(Avalonia.Threading.DispatcherFrame frame) Línea 53	C#
Avalonia.Base.dll!Avalonia.Threading.Dispatcher.MainLoop(System.Threading.CancellationToken cancellationToken) Línea 81	C#
Avalonia.Controls.dll!Avalonia.Controls.ApplicationLifetimes.ClassicDesktopStyleApplicationLifetime.Start(string[] args) Línea 128	C#
Avalonia.Controls.dll!Avalonia.ClassicDesktopStyleApplicationLifetimeExtensions.StartWithClassicDesktopLifetime(Avalonia.AppBuilder builder, string[] args, Avalonia.Controls.ShutdownMode shutdownMode) Línea 220	C#
ZXBasicStudio.dll!ZXBasicStudio.Program.Main(string[] args) Línea 23	C#
@mpietrowicz
Copy link

The same in my app :
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.NullReferenceException: Object reference not set to an instance of an object. at AvaloniaEdit.CodeCompletion.CompletionList.SelectItemFiltering(String query) at AvaloniaEdit.CodeCompletion.CompletionList.SelectItem(String text) at AvaloniaEdit.CodeCompletion.CompletionWindow.CaretPositionChanged(Object sender, EventArgs e) at AvaloniaEdit.Editing.Caret.OnDocumentUpdateFinished() at AvaloniaEdit.Editing.TextArea.OnUpdateFinished(Object sender, EventArgs e) --- End of inner exception stack trace --- at System.RuntimeMethodHandle.InvokeMethod(Object target, Span1& arguments, Signature sig, Boolean constructor, Boolean wrapExceptions)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at System.Delegate.DynamicInvokeImpl(Object[] args)
at System.Delegate.DynamicInvoke(Object[] args)
at AvaloniaEdit.Utils.WeakEventManagerBase4.WeakHandlerList.DeliverEvent(Object sender, TEventArgs args) at AvaloniaEdit.Utils.WeakEventManagerBase4.PrivateDeliverEvent(Object sender, TEventArgs args)
at AvaloniaEdit.Utils.WeakEventManagerBase4.DeliverEvent(Object sender, TEventArgs args) at AvaloniaEdit.Document.TextDocument.EndUpdate() at AvaloniaEdit.Document.TextDocument.Replace(Int32 offset, Int32 length, ITextSource text, OffsetChangeMap offsetChangeMap) at AvaloniaEdit.Document.TextDocument.Insert(Int32 offset, String text) at AvaloniaEdit.Editing.EmptySelection.ReplaceSelectionWithText(String newText) at AvaloniaEdit.Editing.TextArea.ReplaceSelectionWithText(String newText) at AvaloniaEdit.Editing.TextArea.PerformTextInput(TextInputEventArgs e) at AvaloniaEdit.Editing.TextArea.OnTextInput(TextInputEventArgs e) at Avalonia.Input.InputElement.<>c.<.cctor>b__32_4(InputElement x, TextInputEventArgs e) at Avalonia.Interactivity.RoutedEvent1.<>c__DisplayClass1_01.<AddClassHandler>g__Adapter|0(Object sender, RoutedEventArgs e) at Avalonia.Interactivity.RoutedEvent.<>c__DisplayClass23_0.<AddClassHandler>b__0(ValueTuple2 args)
at Avalonia.Reactive.AnonymousObserver1.OnNext(T value) at Avalonia.Reactive.LightweightObservableBase1.PublishNext(T value)
at Avalonia.Reactive.LightweightSubject1.OnNext(T value) at Avalonia.Interactivity.RoutedEvent.InvokeRaised(Object sender, RoutedEventArgs e) at Avalonia.Interactivity.EventRoute.RaiseEventImpl(RoutedEventArgs e) at Avalonia.Interactivity.EventRoute.RaiseEvent(Interactive source, RoutedEventArgs e) at Avalonia.Interactivity.Interactive.RaiseEvent(RoutedEventArgs e) at Avalonia.Input.KeyboardDevice.ProcessRawEvent(RawInputEventArgs e) at Avalonia.Input.InputManager.ProcessInput(RawInputEventArgs e) at Avalonia.Controls.TopLevel.HandleInput(RawInputEventArgs e) at Avalonia.Win32.WindowImpl.AppWndProc(IntPtr hWnd, UInt32 msg, IntPtr wParam, IntPtr lParam) at Avalonia.Win32.WindowImpl.WndProc(IntPtr hWnd, UInt32 msg, IntPtr wParam, IntPtr lParam) at Avalonia.Win32.Interop.UnmanagedMethods.DispatchMessage(MSG& lpmsg) at Avalonia.Win32.Win32DispatcherImpl.RunLoop(CancellationToken cancellationToken) at Avalonia.Threading.DispatcherFrame.Run(IControlledDispatcherImpl impl) at Avalonia.Threading.Dispatcher.PushFrame(DispatcherFrame frame) at Avalonia.Threading.Dispatcher.MainLoop(CancellationToken cancellationToken) at Avalonia.Controls.ApplicationLifetimes.ClassicDesktopStyleApplicationLifetime.Start(String[] args) at Avalonia.ClassicDesktopStyleApplicationLifetimeExtensions.StartWithClassicDesktopLifetime(AppBuilder builder, String[] args, ShutdownMode shutdownMode)

System.NullReferenceException: Object reference not set to an instance of an object. at AvaloniaEdit.CodeCompletion.CompletionList.SelectItemFiltering(String query) at AvaloniaEdit.CodeCompletion.CompletionList.SelectItem(String text) at AvaloniaEdit.CodeCompletion.CompletionWindow.CaretPositionChanged(Object sender, EventArgs e) at AvaloniaEdit.Editing.Caret.OnDocumentUpdateFinished() at AvaloniaEdit.Editing.TextArea.OnUpdateFinished(Object sender, EventArgs e)

@MihaMarkic
Copy link
Contributor

This is probably a duplicate of #449 (or better, the other way round) and has been fixed by #452

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants