question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Microsoft.SqlServer.Server conflicts between S.D.SqlClient and M.D.SqlClient

See original GitHub issue

As 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:

  1. Create a new project
  2. Reference both the Microsoft.AspNetCore.App package and the Microsoft.Data.SqlClient package
  3. 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:closed
  • Created 4 years ago
  • Comments:28 (14 by maintainers)

github_iconTop GitHub Comments

2reactions
DannyMeistercommented, Jun 17, 2019

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:

  <Target Name="ResolveNamespaceConflict" BeforeTargets="FindReferenceAssembliesForReferences;ResolveReferences">
    <ItemGroup>
      <ReferencePath Condition="'%(FileName)' == 'Microsoft.Data.SqlClient'">
        <Aliases>MDSqlClient</Aliases>
      </ReferencePath>
    </ItemGroup>
  </Target>

In my .cs file in this project:

extern alias MDSqlClient;
using MDSqlClient::Microsoft.SqlServer.Server;

[...snip...]

	IEnumerable<SqlDataRecord> Entities { get; set; }
2reactions
mgravellcommented, May 10, 2019

@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?

Read more comments on GitHub >

github_iconTop Results From Across the Web

No results found

github_iconTop Related Medium Post

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found