Microsoft.SqlServer.Server conflicts between S.D.SqlClient and M.D.SqlClient
See original GitHub issueAs soon as I reference this package from a 2.2 project with a reference to “Microsoft.AspNetCore.App” I get the following error:
CS0433 The type 'SqlDataRecord' exists in both 'Microsoft.Data.SqlClient, Version=1.0.19128.1, Culture=neutral, PublicKeyToken=23ec7fc2d6eaa4a5' and 'System.Data.SqlClient, Version=4.5.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'
Repro:
- Create a new project
- Reference both the Microsoft.AspNetCore.App package and the Microsoft.Data.SqlClient package
- Use a type from the package
using Microsoft.SqlServer.Server;
namespace ConsoleApp44
{
class Program
{
static void Main(string[] args)
{
var sqlDataRecord = new SqlDataRecord();
}
}
}
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.2</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Data.SqlClient" Version="1.0.19128.1-Preview" />
<PackageReference Include="Microsoft.AspNetCore.App" />
</ItemGroup>
</Project>
It apparently works on .NET Core 3.0 with FrameworkReference, atleast I don’t get any error
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Data.SqlClient" Version="1.0.19128.1-Preview" />
<FrameworkReference Include="Microsoft.AspNetCore.App" />
</ItemGroup>
</Project>
dotnet --info
.NET Core SDK (gemäß "global.json"):
Version: 3.0.100-preview4-010643
Commit: 88e7cb2515
Laufzeitumgebung: OS Name: Windows OS Version: 10.0.17134 OS Platform: Windows RID: win10-x64 Base Path: C:\Program Files\dotnet\sdk\3.0.100-preview4-010643\
Host (useful for support): Version: 3.0.0-preview4-27506-14 Commit: 98641ad643
Issue Analytics
- State:
- Created 4 years ago
- Comments:28 (14 by maintainers)
Top Results From Across the Web
No results found
Top Related Medium Post
No results found
Top Related StackOverflow Question
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
If anyone ends up here needing a temporary work around, here’s one that worked for me.
Background for my use case: I have a project that needs to use SqlDataRecord and tries to do so via referencing package Microsoft.Data.SqlClient. It appears to be gettings its conflict via some kind of transitive dependency within Microsoft.NETCore.Platforms (3.0.0 preview). I’m using an extern alias to alias the Microsoft.Data.SqlClient copy of the conflicting namespace.
In my .csproj:
In my .cs file in this project:
@David-Engel question, though: there are scenarios where those types are useful today; if you remove them from the public API in M.D, will they work with S.D? Example: the TVP scenario mentioned above. I don’t know how often SqlMetaData is used (not one I’m very familiar with). If they don’t work, there may be an API gap. If they do work inwards, you’d presumably need to use reflection. And I’m not sure they could ever work outwards reliably.
Follow up question: is there no imaginative alternative namespace that could be used instead, even if slightly ugly?