Skip to content

Commit 6c54ede

Browse files
authored
Change TypeMapLazyDictionary to use direct cast instead of 'as' operator for RuntimeAssembly (#122885)
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.
1 parent 6707b81 commit 6c54ede

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/TypeMapLazyDictionary.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,11 +192,11 @@ private static unsafe CallbackContext CreateMaps(
192192
RuntimeAssembly? startingAssembly;
193193
if (AppContext.GetData("System.Runtime.InteropServices.TypeMappingEntryAssembly") is string entryAssemblyName)
194194
{
195-
startingAssembly = Assembly.Load(entryAssemblyName) as RuntimeAssembly;
195+
startingAssembly = (RuntimeAssembly?)Assembly.Load(entryAssemblyName);
196196
}
197197
else
198198
{
199-
startingAssembly = Assembly.GetEntryAssembly() as RuntimeAssembly;
199+
startingAssembly = (RuntimeAssembly?)Assembly.GetEntryAssembly();
200200
}
201201

202202
if (startingAssembly is null)

0 commit comments

Comments
 (0)