Skip to content

Get ambiguous type identity error when using package 'Microsoft.CodeAnalysis.CSharp/2.0.0' in a project that targets 'netcoreapp2.0' #20861

Closed

Description

@daxian-dbw

I ran into this when using the package Microsoft.CodeAnalysis.CSharp/2.0.0 (2.0.0 is the latest version I can find) in my project targeting netcoreapp2.0. Microsoft.CodeAnalysis.CSharp/2.0.0 depends on Microsoft.CodeAnalysis.Common/2.0.0 which pulls in System.ValueTuple/4.3.0. However, the types in System.ValueTuple.dll are already exposed from System.Runtime.dll when targeting netcoreapp2.0, and thus using any of those types results in ambiguous type identity error:

Program.cs(9,45): error CS0433: The type 'TupleExtensions' exists in both 'System.ValueTuple, Version=4.0.1.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' and 'System.Runtime, Version=4.2.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' [D:\apps\netcore2\test\test.csproj]

Here is a simple repro:

using System;

namespace test
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine(typeof(System.TupleExtensions).FullName);
        }
    }
}

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>netcoreapp2.0</TargetFramework>
    <RuntimeIdentifier>win10-x64</RuntimeIdentifier>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="2.0.0" />
  </ItemGroup>

</Project>

It looks netcoreapp2.0 doesn't come with Microsoft.CodeAnalysis.CSharp.dll and Microsoft.CodeAnalysis.dll. How should I consume the Microsoft.CodeAnalysis.CSharp package then?

Activity

  1. karelz commented on Apr 2, 2017

    @karelz
    Member

    @weshaggard @ericeil @jcouv what is the story around ValueTuple? I know it was somewhat special, but don't remember details ...

    cc @terrajobst

  2. jcouv commented on Apr 2, 2017

    @jcouv
    Contributor

    CoreFx was updated to type-forward to System.Runtime (PR dotnet/corefx#14786).
    But this was done after the initial release of the ValueTuple package (4.3.0).
    @ericstj is about to publish an updated package (for mono), which I suspect will also contain those type-forwards. I'll let him confirm if that's the case.

  3. weshaggard commented on Apr 3, 2017

    @weshaggard
    Member

    This is because ValueTuple hasn't been added to the shared framework yet. I'm going to take care of this today.

    @daxian-dbw you can workaround this issue by referencing the latest System.ValueTuple package from myget (https://dotnet.myget.org/feed/dotnet-core/package/nuget/System.ValueTuple/4.4.0-preview1-25203-01).

  4. daxian-dbw commented on Apr 3, 2017

    @daxian-dbw
    ContributorAuthor

    @weshaggard it works fine after referencing to a recent version of System.ValueTuple package. Thanks!

    This is because ValueTuple hasn't been added to the shared framework yet.

    I guess once ValueTuple is added to the shared framework, I won't need to reference to System.ValueTuple/4.4.0-preview1-25203-01 in order to use Microsoft.CodeAnalysis.CSharp/2.0.0, is that correct?

  5. weshaggard commented on Apr 3, 2017

    @weshaggard
    Member

    I guess once ValueTuple is added to the shared framework, I won't need to reference to System.ValueTuple/4.4.0-preview1-25203-01 in order to use Microsoft.CodeAnalysis.CSharp/2.0.0, is that correct?

    That's correct.

  6. danmoseley commented on Apr 3, 2017

    @danmoseley
    Contributor

    @daxian-dbw sounds like this is resolved, I"ll close , feel free to reopen

  7. jcouv commented on May 12, 2017

    @jcouv
    Contributor

    @weshaggard I'm not very familiar with the concept of shared framework. I looked at your PRs from early April. I saw you did some netstandard changes (both in corefx and standard repos) for ValueTuple. Were those related to the shared framework?

  8. weshaggard commented on May 12, 2017

    @weshaggard
    Member

    I did a lot of changes you will need to be more specific. I can tell you that ValueTuple has been added to the shared framework for .NET Core.

  9. jcouv commented on May 12, 2017

    @jcouv
    Contributor

    Cool. That addresses my question. Thanks! :-)

  10. transferred this issue fromdotnet/corefxon Jan 31, 2020
  11. added this to the 2.0.0 milestone on Jan 31, 2020
  12. ghost locked as resolved and limited conversation to collaborators on Dec 24, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-Infrastructure-librariesquestionAnswer questions and provide assistance, not an issue with source code or documentation.

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions