Dhanuka777
Dhanuka777

Reputation: 8636

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?

Upvotes: 4

Views: 4029

Answers (3)

Shimmy Weitzhandler
Shimmy Weitzhandler

Reputation: 104811

I faced this issue in an ASP.NET Core app, and this answer solved my issue quickly.

Upvotes: 0

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.

Upvotes: 10

Rohit
Rohit

Reputation: 965

Some methods/properties/interfaces are duplicated in above 2 dlls.

Remove StackExchange.Redis reference to resolve errors.

Upvotes: 4

Related Questions