Object of type 'Microsoft.CodeAnalysis.Formatting.FormattingOptions+IndentStyle' cannot be converted to type 'Microsoft.CodeAnalysis.Indentation.IndentationOptions'

I am getting this error whenever I enter a newline in the wpf code editor. This is a very high severity issue as it effectively makes the editor non functional.

<PackageReference Include="Alternet.Studio.Editor.Wpf" Version="8.1.4" />
<PackageReference Include="Alternet.Studio.Syntax.Parsers.Roslyn" Version="8.1.4" />

I am using version 4.3.1 of Microsoft.CodeAnalysis.*

System.ArgumentException
  HResult=0x80070057
  Message=Object of type 'Microsoft.CodeAnalysis.Formatting.FormattingOptions+IndentStyle' cannot be converted to type 'Microsoft.CodeAnalysis.Indentation.IndentationOptions'.
  Source=System.Private.CoreLib
  StackTrace:
   at System.RuntimeType.TryChangeType(Object value, Binder binder, CultureInfo culture, Boolean needsSpecialCast)
   at System.RuntimeType.CheckValue(Object value, Binder binder, CultureInfo culture, BindingFlags invokeAttr)
   at System.Reflection.MethodBase.CheckArguments(StackAllocedArguments& stackArgs, ReadOnlySpan`1 parameters, Binder binder, BindingFlags invokeAttr, CultureInfo culture, Signature sig)
   at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   at Alternet.Syntax.Parsers.Roslyn.IndentationProvider.PerLanguageIndentationProvider.GetIndent(Document document, Int32 line, CancellationToken cancellationToken)
   at Alternet.Syntax.Parsers.Roslyn.CodeCompletion.RoslynRepository.GetSmartIndent(Int32 index, Boolean autoIndent, Boolean useSpaces, Int32 spacesInTab)
   at Alternet.Editor.Wpf.TextSource.GetAutoIndent(Int32 line)
   at Alternet.Editor.Wpf.TextSource.NewLine(String& indent, Boolean withChange)
   at Alternet.Editor.Wpf.Selection.NewLine()
   at Alternet.Editor.Wpf.KeyList.ExecuteKey(Keys keys, Int32& state)
   at Alternet.Editor.Wpf.TextEditor.OnKeyDown(KeyEventArgs e)
   at System.Windows.UIElement.OnKeyDownThunk(Object sender, KeyEventArgs e)
   at System.Windows.Input.KeyEventArgs.InvokeEventHandler(Delegate genericHandler, Object genericTarget)
   at System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target)
   at System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs)
   at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
   at System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args)
   at System.Windows.UIElement.RaiseTrustedEvent(RoutedEventArgs args)
   at System.Windows.Input.InputManager.ProcessStagingArea()
   at System.Windows.Input.InputManager.ProcessInput(InputEventArgs input)
   at System.Windows.Input.InputProviderSite.ReportInput(InputReport inputReport)
   at System.Windows.Interop.HwndKeyboardInputProvider.ReportInput(IntPtr hwnd, InputMode mode, Int32 timestamp, RawKeyboardActions actions, Int32 scanCode, Boolean isExtendedKey, Boolean isSystemKey, Int32 virtualKey)
   at System.Windows.Interop.HwndKeyboardInputProvider.ProcessKeyAction(MSG& msg, Boolean& handled)
   at System.Windows.Interop.HwndSource.CriticalTranslateAccelerator(MSG& msg, ModifierKeys modifiers)
   at System.Windows.Interop.HwndSource.OnPreprocessMessage(Object param)
   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)
   at System.Windows.Threading.Dispatcher.LegacyInvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Int32 numArgs)
   at System.Windows.Threading.Dispatcher.Invoke(DispatcherPriority priority, Delegate method, Object arg)
   at System.Windows.Interop.HwndSource.OnPreprocessMessageThunk(MSG& msg, Boolean& handled)
   at System.Windows.Interop.HwndSource.WeakEventPreprocessMessage.OnPreprocessMessage(MSG& msg, Boolean& handled)
   at System.Windows.Interop.ComponentDispatcherThread.RaiseThreadMessage(MSG& msg)
   at System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame frame)
   at System.Windows.Threading.Dispatcher.PushFrame(DispatcherFrame frame)
   at System.Windows.Threading.Dispatcher.Run()
   at System.Windows.Application.RunDispatcher(Object ignore)
   at System.Windows.Application.RunInternal(Window window)
   at System.Windows.Application.Run()
   at MyApp.App.Main()

Hi Gregory,

At the time of releasing 8.1 Roslyn 4.3.1 was still in beta, so our Alternet.Studio.Syntax.Parsers.Roslyn package uses version 4.2.0. With this version autoindent works as expected.

We will look at supporting 4.3.1 shortly, until then it would be the best to use 4.2.0.

Kind regards,
Dmitry

1 Like

Hi Gregory,

We have just pushed an update to NuGet (version 8.1.6), which is compatible with Roslyn 4.3.1.
We still use 4.2.0 by default, but it no longer crashes when you press Enter key if you update it to the newer Roslyn version.

Kind regards,
Dmitry

1 Like