From bf77c78f24cb2d0c9e91756801b0bacc7bbe9dfd Mon Sep 17 00:00:00 2001 From: msbw2 Date: Mon, 14 Oct 2024 09:45:31 -0700 Subject: [PATCH] Fix reflection in MemoryCache tests to support both versions seen in .NET 9 RCs (#3085) --- .../Microsoft.Identity.Web.Test/CacheEncryptionTests.cs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/tests/Microsoft.Identity.Web.Test/CacheEncryptionTests.cs b/tests/Microsoft.Identity.Web.Test/CacheEncryptionTests.cs index a92592f15..b54b61bb8 100644 --- a/tests/Microsoft.Identity.Web.Test/CacheEncryptionTests.cs +++ b/tests/Microsoft.Identity.Web.Test/CacheEncryptionTests.cs @@ -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