Skip to content

Commit bf77c78

Browse files
authored
Fix reflection in MemoryCache tests to support both versions seen in .NET 9 RCs (#3085)
1 parent 78719ac commit bf77c78

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

tests/Microsoft.Identity.Web.Test/CacheEncryptionTests.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,12 @@ private byte[] GetFirstCacheValue(MemoryCache memoryCache)
7979
.GetType()
8080
.GetField("_coherentState", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic)!
8181
.GetValue(memoryCache)!;
82-
memoryCacheContent = (content1?
83-
.GetType()
84-
.GetProperty("EntriesCollection", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic)
82+
Type? content1Type = content1?.GetType();
83+
// The internals of CoherentState seem to change between .NET 9 RCs
84+
memoryCacheContent = ((
85+
content1Type?.GetProperty("_entries", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic) ??
86+
content1Type?.GetProperty("_stringEntries", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic)
87+
)
8588
.GetValue(content1) as IDictionary)!;
8689
#else
8790
memoryCacheContent = (memoryCache

0 commit comments

Comments
 (0)