From e96c693851a2e4be14a9e7fd835c4087b063dc58 Mon Sep 17 00:00:00 2001
From: Mark Wallace <127216156+markwallace-microsoft@users.noreply.github.com>
Date: Fri, 21 Mar 2025 18:56:12 +0000
Subject: [PATCH] .Net: Encode Kusto keys that contain a ' (#11114)

### Motivation and Context

<!-- Thank you for your contribution to the semantic-kernel repo!
Please help reviewers and future users, providing the following
information:
  1. Why is this change required?
  2. What problem does it solve?
  3. What scenario does it contribute to?
  4. If it fixes an open issue, please link to the issue here.
-->

### Description

<!-- Describe your changes, the overall approach, the underlying design.
These notes will help understanding how your code works. Thanks! -->

### Contribution Checklist

<!-- Before submitting this PR, please make sure: -->

- [ ] The code builds clean without any errors or warnings
- [ ] The PR follows the [SK Contribution
Guidelines](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md)
and the [pre-submission formatting
script](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md#development-scripts)
raises no violations
- [ ] All unit tests pass, and I have added new tests where possible
- [ ] I didn't break anyone :smile:
---
 .../src/Connectors/Connectors.Memory.Kusto/KustoMemoryStore.cs  | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/dotnet/src/Connectors/Connectors.Memory.Kusto/KustoMemoryStore.cs b/dotnet/src/Connectors/Connectors.Memory.Kusto/KustoMemoryStore.cs
index 5e28a7a8a016..845adadf87b5 100644
--- a/dotnet/src/Connectors/Connectors.Memory.Kusto/KustoMemoryStore.cs
+++ b/dotnet/src/Connectors/Connectors.Memory.Kusto/KustoMemoryStore.cs
@@ -104,7 +104,7 @@ public async IAsyncEnumerable<MemoryRecord> GetBatchAsync(
         bool withEmbeddings = false,
         [EnumeratorCancellation] CancellationToken cancellationToken = default)
     {
-        var inClauseValue = string.Join(",", keys.Select(k => $"'{k}'"));
+        var inClauseValue = string.Join(",", keys.Select(k => $"'{k.Replace("'", "''")}'"));
         var query = $"{this.GetBaseQuery(collectionName)} " +
             $"| where Key in ({inClauseValue}) " +
             "| project " +