Wpf: RichTextBox throws XamlParseException in its constructor

Created on 5 Jul 2019  ·  10Comments  ·  Source: dotnet/wpf

  • .NET Core Version: 3.0 preview 6
  • Windows version: Windows 10 x64 zh-CN 18362.207
  • Does the bug reproduce also in WPF for .NET Framework 4.8?: No

    Problem description:
    The constructor of RichTextBox crashes when running on Windows 10 1903 Chinese Simplified.
    Similar to #1003

    Actual behavior:
    ($exception).StackTrace

 An unhandled exception of type 'System.Windows.Markup.XamlParseException' occurred in System.Private.CoreLib.dll
“对类型“System.Windows.Controls.RichTextBox”的构造函数执行符合指定的绑定约束的调用时引发了异常。”,行号为“10”,行位置为“10”。

DirectCast(($exception)._innerException, System.ArgumentException).Message

Requested value '删除' was not found.

($exception)._innerException.StackTrace

   at System.Enum.TryParseByName(RuntimeType enumType, String originalValueString, ReadOnlySpan`1 value, Boolean ignoreCase, Boolean throwOnFailure, UInt64& result)
   at System.Enum.TryParseInt32Enum(RuntimeType enumType, String originalValueString, ReadOnlySpan`1 value, Int32 minInclusive, Int32 maxInclusive, Boolean ignoreCase, Boolean throwOnFailure, TypeCode type, Int32& result)
   at System.Enum.TryParse(Type enumType, String value, Boolean ignoreCase, Boolean throwOnFailure, Object& result)
   at System.Enum.Parse(Type enumType, String value, Boolean ignoreCase)
   at System.Windows.Input.KeyConverter.GetKey(String keyToken, CultureInfo culture)
   at System.Windows.Input.KeyConverter.ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, Object source)
   at System.Windows.Input.KeyGestureConverter.ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, Object source)
   at System.ComponentModel.TypeConverter.ConvertFromInvariantString(String text)
   at System.Windows.Input.KeyGesture.CreateFromResourceStrings(String keyGestureToken, String keyDisplayString)
   at MS.Internal.Commands.CommandHelpers.RegisterCommandHandler(Type controlType, RoutedCommand command, ExecutedRoutedEventHandler executedRoutedEventHandler, CanExecuteRoutedEventHandler canExecuteRoutedEventHandler, String srid1, String srid2)
   at System.Windows.Documents.TextEditorTyping._RegisterClassHandlers(Type controlType, Boolean registerEventListeners)
   at System.Windows.Documents.TextEditor.RegisterCommandHandlers(Type controlType, Boolean acceptsRichContent, Boolean readOnly, Boolean registerEventListeners)
   at System.Windows.Controls.RichTextBox..ctor(FlowDocument document)
   at System.Windows.Baml2006.WpfSharedBamlSchemaContext.<>c.<Create_BamlType_RichTextBox>b__923_0()
   at System.Windows.Baml2006.WpfKnownTypeInvoker.CreateInstance(Object[] arguments)
   at MS.Internal.Xaml.Runtime.ClrObjectRuntime.CreateInstanceWithCtor(XamlType xamlType, Object[] args)
   at MS.Internal.Xaml.Runtime.ClrObjectRuntime.CreateInstance(XamlType xamlType, Object[] args)

Expected behavior:
RichTextBox should not throw exception.

Minimal repro:
Drag a RichTextBox control into MainWindow.xaml.

<Window x:Class="MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:RichTextTest"
        mc:Ignorable="d"
        Title="MainWindow" Height="450" Width="800">
    <Grid>
        <RichTextBox/>
    </Grid>
</Window>
issue-type-bug needs-author-feedback

All 10 comments

This should be fixed by #919. I don't know when the next preview will be released but if you don't want to wait you could try nightly builds as described here or you can work around the bug by setting the culture to english during startup (CultureInfo.CurrentUICulture = CultureInfo.GetCultureInfo("en-US");).

@Nukepayload2 please use the nightly build to confirm that this is fixed.

what happened to preview7 anyways, considering the downloads are still on preview6 but nightlies are already on preview8 ?

P7 is in validation now - should be announced as soon as it’s signed off by all teams.

/cc @jamshedd , @leecow

@grubioe
I don't know whether this issue has been fixed, because my program crashed before calling the constructor of RichTextBox.

image

I'll try again after #1183 is solved.

@weltkante, as you noticed master has moved on to Preview 8, this is because the Preview 7 release is in lock down (final stabilization). Preview 7 will be available very soon (next couple of weeks).

@Nukepayload2 you are hitting https://github.com/dotnet/wpf/issues/1183

From https://github.com/dotnet/wpf/issues/1183#issuecomment-510215979

This is now fixed in the latest build available at https://github.com/dotnet/core-sdk.

The current version which I just I checked is:

fc226794a12bfcfc18bac269bc57c7900e4a1e5d
3.0.100-preview8-012990

Please try the latest SDK - you should no longer get the TypeLoadException related to XamlAccessLevel.

It's fixed in the latest SDK.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

JeroenOortwijn picture JeroenOortwijn  ·  3Comments

Normandy picture Normandy  ·  3Comments

bugproof picture bugproof  ·  3Comments

daniel-white picture daniel-white  ·  3Comments

lisberPontes picture lisberPontes  ·  3Comments