16

I'm starting a new project using StackExchange.Redis and .Net Core 2.0. But I get a conflict:

The type 'ConnectionMultiplexer' exists in both 'StackExchange.Redis.StrongName, Version=1.2.4.0, Culture=neutral, PublicKeyToken=c219ff1ca8c2ce46' and 'StackExchange.Redis, Version=1.2.6.0, Culture=neutral, PublicKeyToken=null'

Why is this showing even thou I'm not referencing StackExchange.Redis.StrongName and it's not even the same assembly version?

Lejdholt
  • 532
  • 7
  • 21
  • 1
    Duplicate question here: https://stackoverflow.com/questions/46029281/vs-net-2017-forces-using-stackexchange-redis-1-2-4-0-in-asp-net-2-0-core-app – Mani Gandham Sep 05 '17 at 16:08

4 Answers4

19

I found my solution here.

By adding this (below) to my csproj:

<Target Name="ChangeAliasesOfStrongNameAssemblies" BeforeTargets="FindReferenceAssembliesForReferences;ResolveReferences">
  <ItemGroup>
    <ReferencePath Condition="'%(FileName)' == 'StackExchange.Redis.StrongName'">
      <Aliases>signed</Aliases>
    </ReferencePath>
  </ItemGroup>
</Target>
Stephen Rauch
  • 47,830
  • 31
  • 106
  • 135
Alvin Lim
  • 191
  • 1
  • 3
5

It is possible to use Strongname in your entire application, 1.2.6 is newer and will be used. The problem is when you add Redis.Stackexchange you will have the same namespace from two different dll's. .Net compiler doesn't know which one to use. If you need 1.2.6, use the StrongName version throughout your application and no more problems ....

André
  • 750
  • 11
  • 24
4

I added a conditional flag to the "StackExchange.Redis" package, that makes it work. I Tried this solution on two new projects on two machines. Don't ask me why it works tho.

    <Project Sdk="Microsoft.NET.Sdk.Web">
      <PropertyGroup>
        <TargetFramework>netcoreapp2.0</TargetFramework>
      </PropertyGroup>

      <ItemGroup>
        <Folder Include="wwwroot\" />
      </ItemGroup>

      <ItemGroup>
        <PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.0" />
      </ItemGroup> 
      <ItemGroup Condition=" '$(TargetFramework)' == 'netstandard2.0' ">
        <PackageReference Include="StackExchange.Redis" Version="1.2.6" />
      </ItemGroup>

    </Project>
Shimmy Weitzhandler
  • 101,809
  • 122
  • 424
  • 632
Lejdholt
  • 532
  • 7
  • 21
  • I cannot get your solution to work. This is my config: ` ` Any idea? – Nodios Jan 17 '18 at 13:01
  • Try to move inside the same ItemGroup as StackExchange.Redis.StrongName, maybe that will work. I haven't worked with Redis anything since this post, so can't swear it will work. – Lejdholt Jan 19 '18 at 07:47
  • Did you find any solution to fix the mentioned issues ? – IamChandu Jul 20 '18 at 08:07
0

Microsoft.Extensions.Caching.Redis 2.0 that ships with Asp .Net Core 2.0 internally uses StackExchange.Redis.StrongName, Version=1.2.4.0, that there is for example in C:\Program Files\dotnet\sdk\NuGetFallbackFolder\stackexchange.redis.strongname\1.2.4\lib\netstandard1.5 folder.

So looks it's causes a conflict between different versions of StackExchange.Redis.

Glory
  • 1
  • 2