aspnet/Caching

PlatformNotSupportedException - RedisCache .NET Core / macOS

Closed this issue · 1 comments

While testing out RedisCache on macOS I am getting a PlatformNotSupportedException (full details below) whenever I try to get or set a value. Is this a known issue and/or am I doing something wrong? Note that I also tried this in an ASP.NET Core application using the IDistributedCache service from the services IoC. Same result.

OS: macOS Sierra Version 10.12.3
Redis 3.2.8
Microsoft.Extensions.Caching.Redis: 1.1.0 which uses StackExchange.Redis.StrongName: 1.1.605

Example

using System;
using System.Text;
using Microsoft.Extensions.Caching.Distributed;
using Microsoft.Extensions.Caching.Redis;

namespace ConsoleApplication
{
    public class Program
    {
        public static void Main(string[] args)
        {
            var cache = new RedisCache(new RedisCacheOptions
            {
                Configuration = "localhost",
                InstanceName = "SampleInstance"
            });

            var key = "foo";
            cache.Set(key, Encoding.UTF8.GetBytes("bar"), new DistributedCacheEntryOptions());

            var result = cache.GetString(key);
            Console.WriteLine("$Cached value: {result}");
        }
    }
}

Stack trace

Unhandled Exception: System.AggregateException: One or more errors occurred. (This platform does not support connecting sockets to DNS endpoints via the instance Connect and ConnectAsync methods, due to the potential for a host name to map to multiple IP addresses and sockets becoming invalid for use after a failed connect attempt. Use the static ConnectAsync method, or provide to the instance methods the specific IPAddress desired.) 
---> System.PlatformNotSupportedException: This platform does not support connecting sockets to DNS endpoints via the instance Connect and ConnectAsync methods, due to the potential for a host name to map to multiple IP addresses and sockets becoming invalid for use after a failed connect attempt. Use the static ConnectAsync method, or provide to the instance methods the specific IPAddress desired.
   at System.Net.Sockets.Socket.ThrowIfNotSupportsMultipleConnectAttempts()
   at System.Net.Sockets.Socket.BeginConnect(String host, Int32 port, AsyncCallback requestCallback, Object state)
   at System.Net.Sockets.SocketTaskExtensions.<>c.<ConnectAsync>b__5_0(String targetHost, Int32 targetPort, AsyncCallback callback, Object state)
   at System.Threading.Tasks.TaskFactory`1.FromAsyncImpl[TArg1,TArg2](Func`5 beginMethod, Func`2 endFunction, Action`1 endAction, TArg1 arg1, TArg2 arg2, Object state, TaskCreationOptions creationOptions)
   at System.Threading.Tasks.TaskFactory.FromAsync[TArg1,TArg2](Func`5 beginMethod, Action`1 endMethod, TArg1 arg1, TArg2 arg2, Object state)
   at System.Net.Sockets.SocketTaskExtensions.ConnectAsync(Socket socket, String host, Int32 port)
   at StackExchange.Redis.SocketManager.BeginConnect(EndPoint endpoint, ISocketCallback callback, ConnectionMultiplexer multiplexer, TextWriter log)
   at StackExchange.Redis.PhysicalConnection.BeginConnect(TextWriter log)
   at StackExchange.Redis.PhysicalBridge.GetConnection(TextWriter log)
   at StackExchange.Redis.ServerEndPoint..ctor(ConnectionMultiplexer multiplexer, EndPoint endpoint, TextWriter log)
   at StackExchange.Redis.ConnectionMultiplexer.<ReconfigureAsync>d__119.MoveNext()
   --- End of inner exception stack trace ---
   at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)
   at System.Threading.Tasks.Task.Wait(Int32 millisecondsTimeout, CancellationToken cancellationToken)
   at StackExchange.Redis.ConnectionMultiplexer.ConnectImpl(Func`1 multiplexerFactory, TextWriter log)
   at Microsoft.Extensions.Caching.Redis.RedisCache.Connect()
   at Microsoft.Extensions.Caching.Redis.RedisCache.Set(String key, Byte[] value, DistributedCacheEntryOptions options)

there are already many issues open for this on the StackExchange.Redis and dotnet coreclr repos.
You have to use the IP Address for now. (See error message for explanation why).