Skip to content

Commit

Permalink
Fix reflection in MemoryCache tests to support both versions seen in …
Browse files Browse the repository at this point in the history
….NET 9 RCs (#3085)
  • Loading branch information
msbw2 authored Oct 14, 2024
1 parent 78719ac commit bf77c78
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions tests/Microsoft.Identity.Web.Test/CacheEncryptionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,12 @@ private byte[] GetFirstCacheValue(MemoryCache memoryCache)
.GetType()
.GetField("_coherentState", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic)!
.GetValue(memoryCache)!;
memoryCacheContent = (content1?
.GetType()
.GetProperty("EntriesCollection", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic)
Type? content1Type = content1?.GetType();
// The internals of CoherentState seem to change between .NET 9 RCs
memoryCacheContent = ((
content1Type?.GetProperty("_entries", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic) ??
content1Type?.GetProperty("_stringEntries", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic)
)
.GetValue(content1) as IDictionary)!;
#else
memoryCacheContent = (memoryCache
Expand Down

0 comments on commit bf77c78

Please sign in to comment.