Standard: Targeting netstandard2.1 conflicts with System.Data.DataSetExtensions

Created on 21 Oct 2019  路  12Comments  路  Source: dotnet/standard

I'm trying to upgrade my solution to DotNet Core 3. I have references to Entity Framework, which has forced an upgrade to netstandard 2.1.

However, my classes that were using the DataTableExtensions are now unable to compile due to the following error:
[CS0121] The call is ambiguous between the following methods or properties: 'System.Data.DataTableExtensions.AsEnumerable(System.Data.DataTable)' and 'System.Data.DataTableExtensions.AsEnumerable(System.Data.DataTable)'
and also
[CS0433] The type 'TypedTableBase<T>' exists in both 'System.Data.DataSetExtensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' and 'netstandard, Version=2.1.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'

I have removed all Nuget packages for System.Data.DataSetExtensions, but I probably have a transitive dependency somewhere in the graph.

This problem seems to be the same as the previous one in https://github.com/dotnet/corefx/issues/37738.

I would appreciate any workarounds to get my solution compiling as soon as possible.

bug

Most helpful comment

It actually seems like DataSetExtensions was brought as part of the shared framework and that the package was deleted for the latest release and also all types exposed there where moved down to another assembly. Which suggest that all the types that are available in DataSetExtensions via the package when TargetFramework=netstandard2.0 -- however, since we move its type to be part of the framework, it seems all the types are part of netstandard2.1 as well.

So in order to fix your problem, when targeting netstandard2.1 you actually just need to remove your PackageReference to System.Data.DataSetExtensions.

All 12 comments

cc: @ericstj do we need to fix the ns2.1 shims for DataSetExtensions?

Can you upgrade to the latest version of System.Data.DataSetExtensions? We pushed types down from System.Data.DataSetExtensions into .NETCore 3.0 in order to add API. As a result you need to upgrade to the latest version of the package in order to resolve the duplicate type.

I tried both latest and latest preview and it didn't seem to help.

I tried again on a fresh project to eliminate any problems with my personal one.

Using this code:

using System.Data;

public class DataTableTest
{
    public DataTableTest()
    {
        new DataTable().AsEnumerable();
    }
}

This csproj will build:

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>netstandard2.0</TargetFramework>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="System.Data.DataSetExtensions" Version="4.5.0" />
  </ItemGroup>
</Project>

and this one will not

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>netstandard2.1</TargetFramework>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="System.Data.DataSetExtensions" Version="4.5.0" />
  </ItemGroup>
</Project>

It actually seems like DataSetExtensions was brought as part of the shared framework and that the package was deleted for the latest release and also all types exposed there where moved down to another assembly. Which suggest that all the types that are available in DataSetExtensions via the package when TargetFramework=netstandard2.0 -- however, since we move its type to be part of the framework, it seems all the types are part of netstandard2.1 as well.

So in order to fix your problem, when targeting netstandard2.1 you actually just need to remove your PackageReference to System.Data.DataSetExtensions.

If they were part added to netstandard2.1, we should also add the shim to netstandard2.1. Did we do that? /cc @wtgodbe @terrajobst

Conflict resolution should make it so that the shim/facade is preferred over any package version.

Not as far as I remember. This was the change to include new shims in 2.1, which doesn't include system.data: https://github.com/dotnet/standard/commit/d3413ee9ec761bdf067114a498b9da3ebf0149df#diff-a691a0680af7bf87b21e86263f484691

It actually seems like DataSetExtensions was brought as part of the shared framework and that the package was deleted for the latest release and also all types exposed there where moved down to another assembly. Which suggest that all the types that are available in DataSetExtensions via the package when TargetFramework=netstandard2.0 -- however, since we move its type to be part of the framework, it seems all the types are part of netstandard2.1 as well.

So in order to fix your problem, when targeting netstandard2.1 you actually just need to remove your PackageReference to System.Data.DataSetExtensions.

Yes, you're totally right, forgot to do that sorry.
In my real project that didn't help, probably due to transitive dependencies - any workaround there?

Workaround: <PackageReference Include="System.Data.DataSetExtensions" Version="4.5.0" ExcludeAssets="all"/>

This should remove all the assets from that package, even if it came transitively.

Let's move this to standard repo and consider for servicing.

Workaround: <PackageReference Include="System.Data.DataSetExtensions" Version="4.5.0" ExcludeAssets="all"/>

This should remove all the assets from that package, even if it came transitively.

Let's move this to standard repo and consider for servicing.

That works, thank you!

@terrajobst @wtgodbe can this be considered for servicing?

@terrajobst who can look at this for 3.0/3.1 servicing?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

KexyBiscuit picture KexyBiscuit  路  3Comments

valeriob picture valeriob  路  4Comments

virzak picture virzak  路  4Comments

chrisaut picture chrisaut  路  3Comments

tbonham picture tbonham  路  5Comments