Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nuget package 2.1.1 does not declare dependency on System.Runtime.Caching for .NET Standard assemblies #872

Closed
AustinWise opened this issue Jan 10, 2021 · 5 comments · Fixed by #877 or #878

Comments

@AustinWise
Copy link

AustinWise commented Jan 10, 2021

Description

The 2.1.1 nuget package does not declare a dependency on System.Runtime.Caching for the .NET Standard 2.0 and 2.1 runtimes. However these assemblies in the nuget package reference System.Runtime.Caching:

  • runtimes\unix\lib\netstandard2.0\Microsoft.Data.SqlClient.dll
  • runtimes\unix\lib\netstandard2.1\Microsoft.Data.SqlClient.dll
  • runtimes\win\lib\netstandard2.0\Microsoft.Data.SqlClient.dll
  • runtimes\win\lib\netstandard2.1\Microsoft.Data.SqlClient.dll

This can cause a problem if you use functionality that uses classes from System.Runtime.Caching. Addtionally, some frameworks look at assembly metadata and break when assemblies are missing. For example, the Xamarin Mac framework crashes on startup.

To reproduce

I'm using the out-of-support .NET Core 2.0 to demonstrate the issue, since in-support versions of .NET Core are use the .NetCoreApp assemblies from the Nuget package. Other runtimes that support .NET Standard 2.0 should also exhibit this problem.

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

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>netcoreapp2.0</TargetFramework>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.Data.SqlClient" Version="2.1.1" />
  </ItemGroup>

</Project>
using Microsoft.Data.SqlClient;
using System;

class Program
{
    static void Main(string[] args)
    {
        try
        {
            var builder = new SqlConnectionStringBuilder();
            builder.DataSource = ".";
            builder.Authentication = SqlAuthenticationMethod.ActiveDirectoryIntegrated;
            using (var conn = new SqlConnection(builder.ToString()))
            using (var cmd = new SqlCommand("SELECT name FROM SYSOBJECTS WHERE xtype = @type", conn, null, SqlCommandColumnEncryptionSetting.Enabled))
            {
                conn.Open();
                cmd.Parameters.Add(new SqlParameter("type", "u"));
                using (var reader = cmd.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        Console.WriteLine(reader.GetString(0));
                    }
                }
            }
        }
        catch (Exception ex)
        {
            Console.WriteLine(ex);
        }
    }
}

Error on execution:

System.TypeInitializationException: The type initializer for 'Microsoft.Data.SqlClient.SqlQueryMetadataCache' threw an exception. ---> System.IO.FileNotFoundException: Could not load file or assembly 'System.Runtime.Caching, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified.
   at Microsoft.Data.SqlClient.SqlQueryMetadataCache..ctor()
   at Microsoft.Data.SqlClient.SqlQueryMetadataCache..cctor() in /_/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlQueryMetadataCache.cs:line 25
   --- End of inner exception stack trace ---
   at Microsoft.Data.SqlClient.SqlCommand.PrepareForTransparentEncryption(CommandBehavior cmdBehavior, Boolean returnStream, Boolean isAsync, Int32 timeout, TaskCompletionSource`1 completion, Task& returnTask, Boolean asyncWrite, Boolean& usedCache, Boolean inRetry) in /_/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlCommand.cs:line 3327
   at Microsoft.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, TaskCompletionSource`1 completion, Int32 timeout, Task& task, Boolean& usedCache, Boolean asyncWrite, Boolean inRetry, String method) in /_/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlCommand.cs:line 4245
   at Microsoft.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior) in /_/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlCommand.cs:line 1908
   at Microsoft.Data.SqlClient.SqlCommand.ExecuteReader() in /_/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlCommand.cs:line 1872
   at Program.Main(String[] args)

Expected behavior

The Nuget package should declare that the .NET Standard 2.0 and 2.1 runtimes need the System.Runtime.Caching dependancy. The .NETCoreApp 2.1 and 3.1 targets already do that.

@AustinWise AustinWise changed the title Nuget package does not declare dependency on System.Runtime.Caching for .NET Standard assemblies Nuget package 2.1.1 does not declare dependency on System.Runtime.Caching for .NET Standard assemblies Jan 10, 2021
@ErikEJ
Copy link
Contributor

ErikEJ commented Jan 11, 2021

Workaround would be ??

<PackageReference Include="System.Runtime.Caching" Version="4.7.0" />

@cheenamalhotra
Copy link
Member

Acknowledged.
We will address this in next release.

@cheenamalhotra
Copy link
Member

@AustinWise

Please feel free to try the changes from PR #877 and let us know by downloading build NuGet from here: CI Build Artifacts

@AustinWise
Copy link
Author

@cheenamalhotra Thanks, I tried it out and that fixed the problem!
@ErikEJ Yes, that workaround will also work, thanks for pointing that out.

@cheenamalhotra
Copy link
Member

Closing issue as linked PRs are merged, fix will be available in next patch of v2.1 and next preview version onwards,

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants