Skip to content

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
…untimeAssembly

Co-authored-by: jtschuster <36744439+jtschuster@users.noreply.github.com>
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()

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.

3 participants