Skip to content

Fix: Avoid InvalidCastException in TickerQHubNotificationSender occurrence serialization#864

Open
mdemrulkayes wants to merge 1 commit into
Arcenox-co:mainfrom
mdemrulkayes:bugs/InvalidCastExceptionInTickerQHubNotificationSender
Open

Fix: Avoid InvalidCastException in TickerQHubNotificationSender occurrence serialization#864
mdemrulkayes wants to merge 1 commit into
Arcenox-co:mainfrom
mdemrulkayes:bugs/InvalidCastExceptionInTickerQHubNotificationSender

Conversation

@mdemrulkayes

@mdemrulkayes mdemrulkayes commented May 30, 2026

Copy link
Copy Markdown
Contributor

Related Issue

Fixes #863

AddCronOccurrenceAsync and UpdateCronOccurrenceAsync previously hard-cast object occurrence to CronTickerOccurrenceEntity<CronTickerEntity>, throwing InvalidCastException
when a different concrete type was passed

  • Extracted SerializeOccurrence helper that attempts a safe is cast first; falls back to generic JsonSerializer.SerializeToElement with camelCase policy
  • Added static CamelCaseOptions field to avoid allocating JsonSerializerOptions on every fallback call

Root cause

Direct cast (CronTickerOccurrenceEntity<CronTickerEntity>)occurrence fails at runtime when occurrence is a subtype or unrelated type that doesn't satisfy the cast.

Centralize serialization for cron occurrence notifications by adding SerializeOccurrence method. Use source generator context for known types and camelCase options as fallback. Simplifies Add/UpdateCronOccurrenceAsync methods.
@github-actions

github-actions Bot commented May 30, 2026

Copy link
Copy Markdown

All contributors have signed the CLA ✍️ ✅
Posted by the CLA Assistant Lite bot.

@mdemrulkayes

Copy link
Copy Markdown
Contributor Author

I have read the CLA Document and I hereby sign the CLA

github-actions Bot added a commit that referenced this pull request May 30, 2026
@mdemrulkayes mdemrulkayes changed the title #863 fix: avoid InvalidCastException in TickerQHubNotificationSender occurrence serialization Fix: Avoid InvalidCastException in TickerQHubNotificationSender occurrence serialization Jun 7, 2026
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

Successfully merging this pull request may close these issues.

InvalidCastException in TickerQNotificationHubSender when using custom CronTickerEntity

1 participant