Skip to content

Instantly share code, notes, and snippets.

@itn3000
Last active August 5, 2026 01:45
Show Gist options
  • Select an option

  • Save itn3000/bc6c9282a33f455cf7621d5ff86560de to your computer and use it in GitHub Desktop.

Select an option

Save itn3000/bc6c9282a33f455cf7621d5ff86560de to your computer and use it in GitHub Desktop.
StackExchange.Redis error in NativeAOT
using StackExchange.Redis;
namespace clienterrtest;
public class Worker(ILogger<Worker> logger) : BackgroundService
{
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
{
ConnectionMultiplexer? con = null;
try
{
while (!stoppingToken.IsCancellationRequested)
{
try
{
if (con == null)
{
logger.LogInformation("begin connect");
// attempt to connect redis server which does not exist
// connection error is expected
con = await ConnectionMultiplexer.ConnectAsync("localhost:9999", Console.Out);
}
var db = con.GetDatabase();
await db.PingAsync();
logger.LogInformation("end connect");
}
catch (Exception e)
{
logger.LogError(e, "error");
}
await Task.Delay(1000, stoppingToken);
}
}
finally
{
if (con != null)
{
await con.DisposeAsync();
}
}
}
}
info: Microsoft.Hosting.Lifetime[0]
Application started. Press Ctrl+C to shut down.
info: clienterrtest.Worker[0]
begin connect
info: Microsoft.Hosting.Lifetime[0]
Hosting environment: Production
info: Microsoft.Hosting.Lifetime[0]
Content root path: D:\src\dotnet-sandbox\redislabs\clienterrtest
01:22:28.8528: Connecting (async) on .NET 10.0.10 (StackExchange.Redis: v3.1.3.44425)
01:22:28.8551: localhost:9999
01:22:28.8552: localhost:9999/Interactive: Connecting...
01:22:28.8567: localhost:9999: BeginConnectAsync
01:22:28.8589: 1 unique nodes specified (with tiebreaker)
01:22:28.8589: localhost:9999: OnConnectedAsync init (State=Connecting)
01:22:28.8591: Allowing 1 endpoint(s) 00:00:05 to respond...
01:22:28.8592: Awaiting 1 available task completion(s) for 5000ms, IOCP: (Busy=1,Free=767,Min=0,Max=768), WORKER: (Busy=1,Free=767,Min=0,Max=768), POOL: (Threads=2,QueuedItems=0,CompletedItems=0,Timers=1)
01:22:32.9328: localhost:9999: OnConnectedAsync completed (Disconnected)
01:22:32.9329: All 1 available tasks completed cleanly, IOCP: (Busy=2,Free=766,Min=0,Max=768), WORKER: (Busy=2,Free=766,Min=0,Max=768), POOL: (Threads=4,QueuedItems=0,CompletedItems=3,Timers=2)
01:22:32.9331: Endpoint summary:
01:22:32.9331: localhost:9999: Endpoint is (Interactive: Connecting, Subscription: Connecting)
01:22:32.9333: Task summary:
01:22:32.9334: localhost:9999: Returned, but incorrectly
01:22:32.9335: Election summary:
01:22:32.9335: Election: localhost:9999 had no tiebreaker set
01:22:32.9336: Election: No primaries detected
01:22:32.9337: Endpoint Summary:
01:22:32.9338: Server summary: localhost:9999: Standalone v6.0.0, primary; keep-alive: 00:01:00; int: Connecting; sub: n/a; not in use: DidNotRespond, counters: localhost:9999: int ops=0, qu=0, qs=0, qc=0, wr=0, socks=2; sub ops=0, qu=0, qs=0, qc=0, wr=0, profile: localhost:9999: Circular op-count snapshot; int: 0 (0.00 ops/s; spans 10s); sub:
01:22:32.9339: Sync timeouts: 0; async timeouts: 0; fire and forget: 0; last heartbeat: -1s ago
01:22:32.9340: Resetting failing connections to retry...
01:22:32.9341: Retrying - attempts left: 2...
01:22:32.9342: 1 unique nodes specified (with tiebreaker)
01:22:32.9342: localhost:9999: OnConnectedAsync init (State=Disconnected)
01:22:32.9343: Allowing 1 endpoint(s) 00:00:05 to respond...
01:22:32.9344: Awaiting 1 available task completion(s) for 5000ms, IOCP: (Busy=2,Free=766,Min=0,Max=768), WORKER: (Busy=2,Free=766,Min=0,Max=768), POOL: (Threads=4,QueuedItems=0,CompletedItems=7,Timers=0)
Unhandled exception. System.MissingFieldException: Field not found: '_invocationList'.
at StackExchange.Redis.Delegates.s_getArr(MulticastDelegate) + 0x15
at StackExchange.Redis.ConnectionMultiplexer.TryCompleteHandler[T](EventHandler`1, Object, T, Boolean) + 0x4b
at StackExchange.Redis.ConnectionFailedEventArgs.StackExchange.Redis.ICompletable.TryComplete(Boolean) + 0x22
at StackExchange.Redis.ConnectionMultiplexer.<>c.<.cctor>b__85_0(Object) + 0x22
at System.Threading.ThreadPoolWorkQueue.Dispatch() + 0x16a
at System.Threading.WindowsThreadPool.DispatchCallback(IntPtr, IntPtr, IntPtr) + 0x60
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment