Skip to content

Change TypeMapLazyDictionary to use direct cast instead of 'as' operator for RuntimeAssembly#122885

Merged
jtschuster merged 2 commits intomainfrom
copilot/update-lazytypemaps-dictionary
Jan 6, 2026
Merged

Change TypeMapLazyDictionary to use direct cast instead of 'as' operator for RuntimeAssembly#122885
jtschuster merged 2 commits intomainfrom
copilot/update-lazytypemaps-dictionary

Conversation

Copy link
Contributor

Copilot AI commented Jan 5, 2026

Description

Replaced as RuntimeAssembly with direct cast (RuntimeAssembly?) in TypeMapLazyDictionary.CreateMaps() for both Assembly.Load() and Assembly.GetEntryAssembly() calls.

Direct cast surfaces type mismatches as InvalidCastException rather than silently returning null, which is the correct behavior since these methods should always return RuntimeAssembly when non-null in the runtime environment.

Customer Impact

None. This is a code quality improvement addressing review feedback.

Regression

No.

Testing

Existing System.Runtime.InteropServices test suite (2547 tests passed).

Risk

Low. Minimal change to type conversion semantics with identical behavior for valid inputs.

Original prompt

Can you address Aaron's comment and update the code in LazyTypeMapDictionary to cast to RuntimeAssembly instead of using 'as' #121513 (comment)

Create a PR for this.


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI self-assigned this Jan 5, 2026
Copilot AI changed the title [WIP] Update LazyTypeMapDictionary to cast to RuntimeAssembly Change TypeMapLazyDictionary to use direct cast instead of 'as' operator for RuntimeAssembly Jan 5, 2026
Copilot AI requested a review from jtschuster January 5, 2026 18:51
Copy link
Member

@AaronRobinsonMSFT AaronRobinsonMSFT left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

@jtschuster jtschuster marked this pull request as ready for review January 6, 2026 05:03
Copilot AI review requested due to automatic review settings January 6, 2026 05:03
@jtschuster jtschuster merged commit 6c54ede into main Jan 6, 2026
146 of 150 checks passed
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR changes the type conversion approach from the as operator to a direct cast for converting Assembly to RuntimeAssembly? in the TypeMapLazyDictionary.CreateMaps() method. The change affects two calls: Assembly.Load(string) and Assembly.GetEntryAssembly().

Key Changes:

  • Changed Assembly.Load(entryAssemblyName) as RuntimeAssembly to (RuntimeAssembly?)Assembly.Load(entryAssemblyName)
  • Changed Assembly.GetEntryAssembly() as RuntimeAssembly to (RuntimeAssembly?)Assembly.GetEntryAssembly()

@jkotas jkotas deleted the copilot/update-lazytypemaps-dictionary branch January 24, 2026 03:51
@github-actions github-actions bot locked and limited conversation to collaborators Feb 23, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants