Skip to content

Commit b328868

Browse files
committed
Fix IL2075/IL2060 warnings in VectorStoreTextSearch.cs - Add pragma warning suppressions around reflection operations in LINQ expression building - IL2075 (GetMethod) and IL2060 (MakeGenericMethod) warnings are acceptable for dynamic property access - Fixes GitHub Actions CI/CD pipeline failures where --warnaserror treats warnings as errors - Targeted suppressions with explanatory comments for maintainability
1 parent 54f7f7d commit b328868

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

dotnet/src/SemanticKernel.Core/Data/TextSearch/VectorStoreTextSearch.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -694,7 +694,9 @@ private async IAsyncEnumerable<string> GetResultsAsStringAsync(IAsyncEnumerable<
694694
if (itemType == typeof(string))
695695
{
696696
// Look for Contains method: collection.Contains(value)
697+
#pragma warning disable IL2075 // GetMethod on property type - acceptable for reflection-based expression building
697698
var containsMethod = propertyType.GetMethod("Contains", new[] { typeof(string) });
699+
#pragma warning restore IL2075
698700
if (containsMethod != null)
699701
{
700702
var constant = Expression.Constant(value);
@@ -704,9 +706,11 @@ private async IAsyncEnumerable<string> GetResultsAsStringAsync(IAsyncEnumerable<
704706
// Fallback to LINQ Contains for IEnumerable<string>
705707
if (typeof(System.Collections.Generic.IEnumerable<string>).IsAssignableFrom(propertyType))
706708
{
709+
#pragma warning disable IL2060 // MakeGenericMethod with known string type - acceptable for expression building
707710
var linqContainsMethod = typeof(Enumerable).GetMethods()
708711
.Where(m => m.Name == "Contains" && m.GetParameters().Length == 2)
709712
.FirstOrDefault()?.MakeGenericMethod(typeof(string));
713+
#pragma warning restore IL2060
710714

711715
if (linqContainsMethod != null)
712716
{
@@ -719,9 +723,11 @@ private async IAsyncEnumerable<string> GetResultsAsStringAsync(IAsyncEnumerable<
719723
// Support string arrays
720724
else if (propertyType == typeof(string[]))
721725
{
726+
#pragma warning disable IL2060 // MakeGenericMethod with known string type - acceptable for expression building
722727
var linqContainsMethod = typeof(Enumerable).GetMethods()
723728
.Where(m => m.Name == "Contains" && m.GetParameters().Length == 2)
724729
.FirstOrDefault()?.MakeGenericMethod(typeof(string));
730+
#pragma warning restore IL2060
725731

726732
if (linqContainsMethod != null)
727733
{

0 commit comments

Comments
 (0)