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

UnauthorizedAccessException When Setting Content of ReadOnly RichEditBox #10028

Open
D4rk-S0ul opened this issue Sep 30, 2024 · 1 comment
Open
Labels
bug Something isn't working needs-triage Issue needs to be triaged by the area owners

Comments

@D4rk-S0ul
Copy link

D4rk-S0ul commented Sep 30, 2024

Describe the bug

Settings the Content of a RichEditBox in CodeBehind works, but only if IsReadOnly="False".
As soon as I make it ReadOnly, I get the follwing exeption:

System.UnauthorizedAccessException
  HResult=0x80070005
  Message=Attempted to perform an unauthorized operation.
  Source=WinRT.Runtime
  StackTrace:
   at WinRT.ExceptionHelpers.<ThrowExceptionForHR>g__Throw|38_0(Int32 hr)
   at WinRT.ExceptionHelpers.ThrowExceptionForHR(Int32 hr)
   at ABI.Microsoft.UI.Text.ITextDocumentMethods.SetText(IObjectReference _obj, TextSetOptions options, String value)
   at Microsoft.UI.Text.RichEditTextDocument.SetText(TextSetOptions options, String value)
   at RichEditBoxBug.MainWindow.RichEditBox_Loaded(Object sender, RoutedEventArgs e) in C:\Users\User\Documents\Programming\RichEditBoxBug\RichEditBoxBug\MainWindow.xaml.cs:line 26
   at WinRT._EventSource_global__Microsoft_UI_Xaml_RoutedEventHandler.EventState.<GetEventInvoke>b__1_0(Object sender, RoutedEventArgs e)
   at ABI.Microsoft.UI.Xaml.RoutedEventHandler.Do_Abi_Invoke(IntPtr thisPtr, IntPtr sender, IntPtr e)

Steps to reproduce the bug

  1. Create a new packaged app
  2. Add a RichEditBox
  3. Set it's content in CodeBehind using richEditBox.Document.SetText(TextSetOptions.None, "Hello, World!");

Alternatively, the source-code can be found on my GitHub.

Expected behavior

Even according to the official documentation:
IsReadOnly gets or sets a value that indicates whether the user can change the text in the RichEditBox.

Therefore, I expect to be able to set the content of a ReadOnly RichEditBox programmatically. The only effect the ReadOnly state should have is preventing UserInput.

Screenshots

No response

NuGet package version

WinUI 3 - Windows App SDK 1.6.0: 1.6.240829007

Windows version

No response

Additional context

Windows Version: Windows 11 (23H2): Build 22631.4169
--> Please add this Version to the selectable Windows Versions

@D4rk-S0ul D4rk-S0ul added the bug Something isn't working label Sep 30, 2024
@microsoft-github-policy-service microsoft-github-policy-service bot added the needs-triage Issue needs to be triaged by the area owners label Sep 30, 2024
@D4rk-S0ul
Copy link
Author

Is there any further information needed? Just let me know

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working needs-triage Issue needs to be triaged by the area owners
Projects
None yet
Development

No branches or pull requests

1 participant