Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

StackExchange.Redis.IDatabase exists in two dlls

I installed Redis StackExchange nuget and things worked fine. But then I installed RedisSessionStateProvider nuget, which installed StackExchange.Redis.StrongName along with it.

Now I am getting the following error,

Error 107 The type 'StackExchange.Redis.IDatabase' exists in both 'e:\Source\packages\StackExchange.Redis.1.0.481\lib\net45\StackExchange.Redis.dll' and 'e:\Source\packages\StackExchange.Redis.StrongName.1.0.481\lib\net45\StackExchange.Redis.StrongName.dll' E:\Source\MyApp\Helpers\RedisHelper\StackExchangeRedisExtensions.cs 13 37 MyApp

Why is this?

like image 908
Dhanuka777 Avatar asked Dec 08 '22 02:12

Dhanuka777


1 Answers

There's a lot of confusion between the strong-named dll and the non-strong-named dll namespaces.

You can easily solve this by using extern alias.

  1. Right click on project references and pick the dll you want to refer, go to properties window. Then, change the Aliases field value to anything you want. E.g: "Redis".
  2. Then go to your consumer source-file and add:

    extern alias Redis;
    
    using System;
    // ... other references
    using Redis::StackExchange.Redis;
    
    namespace Foo
    {
        public class Program
        {
            public static void Main(string[] args)
            {
                using (ConnectionMultiplexer connection = ConnectionMultiplexer.Connect("myConn"))
                {
                    // use StackExchange API here.
                }
            }
        }
    }
    

There's also an issue on StackExchange's repository explaining more about StrongName vs Non-StrongName.

like image 82
Bernardo Bosak de Rezende Avatar answered Jan 12 '23 12:01

Bernardo Bosak de Rezende