-
Notifications
You must be signed in to change notification settings - Fork 3.4k
[rc2] Fix InvalidCastException in ToDebugString when using IncludeAnnotations with RuntimeNavigation #36651
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
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Co-authored-by: AndriySvyryd <[email protected]>
Copilot
AI
changed the title
[WIP] Debug view threw Unable to cast object of type 'Microsoft.EntityFrameworkCore.Metadata.RuntimeNavigation' to type 'Microsoft.EntityFrameworkCore.Infrastructure.AnnotatableBase'
Fix InvalidCastException in ToDebugString when using IncludeAnnotations with RuntimeNavigation
Aug 26, 2025
…ethods Co-authored-by: AndriySvyryd <[email protected]>
Member
|
@copilot Rewrite the PR summary using this template: |
Contributor
Author
... |
AndriySvyryd
approved these changes
Aug 26, 2025
artl93
approved these changes
Aug 26, 2025
roji
approved these changes
Aug 27, 2025
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #35276
Description
The
ToDebugStringmethods inIReadOnlyNavigation,IReadOnlyProperty,IReadOnlyComplexProperty, andIReadOnlySkipNavigationwere attempting to cast runtime metadata objects toAnnotatableBaseto check theIsReadOnlyproperty for determining when to include property indexes. However, runtime objects inherit fromRuntimeAnnotatableBase, notAnnotatableBase, causing anInvalidCastException.Customer impact
When calling
Model.ToDebugString()withMetadataDebugStringOptions.IncludeAnnotationson a runtime model, applications would crash with "Unable to cast object of type 'RuntimeNavigation' to type 'AnnotatableBase'". Workaround was to avoid usingIncludeAnnotationsflag or avoid callingToDebugStringon runtime models.How found
Customer reported issue. Affects any application attempting to debug or inspect runtime model metadata using the
ToDebugStringmethod with annotation inclusion.Regression
Yes, from 8.0.x
Testing
Changes manually tested by ensuring
ToDebugStringworks correctly with both runtime and design-time models when usingMetadataDebugStringOptions.IncludeAnnotationsandMetadataDebugStringOptions.IncludePropertyIndexes.Risk
Low - The change uses safe type checking patterns and maintains existing behavior while fixing the casting issue. Runtime objects will always show property indexes (appropriate for finalized models) while design-time objects only show them when
IsReadOnlyis true.✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.