TGViewer
Telegram github commits and releases Telegram github commits and releases @tgappsupdates · 4.52K subscribers
Post #20496 121
UnigramDev/Unigram/crash-message-selector-null-content-root • 15b9841 • 1 files, +49/-5
Fix crash when MessageSelector loads before its content is set

MessageSelector.OnLoaded built the TextSelectionManager unconditionally:

_textSelectionManager ??= new TextSelectionManager(this, ContentTemplateRoot);

TextSelectionManager's constructor rejects a null root, so whenever a
container was connected before it had been given content, the constructor
threw ArgumentNullException out of a Loaded handler, which is unhandled and
takes the app down.

Reported by crash telemetry on 12.8.2 ("Value cannot be null. Parameter
name: root"). The reported log tails show it under heavy UI churn — chat
navigation with popups opening — which is when layout is most likely to lag
behind connection.

Attach whenever a content element is actually present instead: on load, and
again from OnContentChanged whenever the content itself changes. The control
is always handed a UIElement directly and is never initialized through a
ContentTemplate, so Content is the element to attach to and ContentTemplateRoot
was the wrong property to read in the first place.

OnContentChanged detaches first. The manager's pointer handlers live on the
previous content element, so they have to come off before attaching to the
new one, or they outlive the element they were added to and the manager keeps
reporting selection for content that is no longer displayed.

EnsureTextSelectionManager also checks IsConnected. Only OnUnloaded and
OnContentChanged detach the manager, so attaching while disconnected would
leave the pointer handlers on the content permanently and, through them, root
the control for the rest of the session.

The four selection accessors dereferenced the manager unconditionally, which
would have turned this window into a NullReferenceException instead; they are
now null-safe.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>

#unigram
  • 🫡 2
More from @tgappsupdates
  1. Oct 16, 2026Ajaxy/telegram-tt/master • b0afc5e • 3 files, +4/-4 12.0.47 Ajaxy/telegram-tt/master • 6bf…
  2. Oct 15, 2026morethanwords/tweb/master • 1b86ca8 • 2 files, +23/-13 Caption field: the AI button sits o…
  3. Oct 15, 2026morethanwords/tweb/master • 7a1c7e2 • 1 files, +11/-2 Retry a language pack update that fa…
  4. Oct 15, 2026TGX-Android/Telegram-X/main • b960f4c • 1 files, +3/-2 Fix displaying call notification in…
  5. Oct 15, 2026TGX-Android/Telegram-X/main • d9d5897 • 1 files, +3/-2 Fix displaying call notifiaction in…
  6. Oct 15, 2026telegramdesktop/tdesktop/dev • 75c0e28 • 2 files, +77/-185 Share the rich editor inline-fi…
Threads Profile ViewerView any public Threads profile without an account.Open ThreadLook →Writing with AI? Make it sound human.Metric37 rewrites AI drafts so they read naturally. Free AI detector, 1,500 words free.Try Metric37 →