-
Notifications
You must be signed in to change notification settings - Fork 300
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
Sni.dll not included in .NET Core 3.x.x shared folder #385
Comments
Hi @RomBrz .NET Core 3.x onwards the new SqlClient library "Microsoft.Data.SqlClient" is used, and it is certainly not the same as before since SNI.dll are now referenced from external packages. But I'm a little confused how SNI.dll was integrated before and shipped with ASP.NET Core App. @ajcvickers In order to understand which SNI.dll library is getting pulled for Microsoft.Data.SqlClient now, I need some background of how ASP.NET integrates with SqlClient. |
I think you might also need to migrate to the new namespace "Microsoft.Data.SqlClient" in order to work with ASP.NET Core 3.x, if not done yet. If your code still references System.Data.SqlClient, that could be the reason it looks for sni.dll in the loaded runtime libraries and works when copied manually. @ajcvickers please correct me if I'm wrong. |
Hi @cheenamalhotra , thanks for helping me with that. My problem is related with permissions and availability of the DLLs. Let my try to explain better: Before .net core 3.0 there were a sni.dll in C:\Program Files (x86)\dotnet\shared\Microsoft.AspNetCore.App\2.2.8, for example, and when i install that on my server, this folder by default has basicaly "Read and Execute" permission for almost everyone, so any application could execute any DLL that exists in this folder. With .NET Core 3.x, the sni.dll don't existis in this shared folder, and the code put that sni.dll in it's own folder. Let me exemplify the default behavior: App2 running with .Core 3.1.1: So with the .NET Core 3.x behavior i have more insecure applications as, to work, i have to give more NTFS permissions to run the "same" code. My workaround is simply get the sni.dll and put inside the C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App\3.1.1\sni.dll, so the App2 in my example will run with "Read Only". Seems like with .NET Core 3.x Microsoft choose to not use sni.dll as a "common dll that should be in default shared dlls" and who wants to use it should put inside your code (and with that opening a security flaw as giving NTFS permission to Execute inside a code isn't a best practice). TL: sni.dll come in .NET 2.x shared folder when you install the server bundle. .NET 3.x didn't come with sni.dll in shared folder, forcing who want's to use to publish inside the project's folder, and with that forcing to give more permissions that should be needed to run compared with an 2.x project. |
@cheenamalhotra With regard to the SNI dependency, this isn't something I am very familiar with. It is likely something that @danmosemsft's team knows more about. @bricelam might also have some ideas. With regards to using ASP.NET Core 3.x, yes, that requires updating to "Microsoft.Data.SqlClient". (This is, of course, assuming that you're using some part of ASP.NET Core that does data access, such as Identity or EF.) |
I wasn't aware of any change to sni.dll deployment between 2.1 and 3.1. Maybe @ericstj can recall. |
We've never included sni.dll in Microsoft.NETCore.App. This has always shipped as a dependency of the SqlClient package: https://www.nuget.org/packages/runtime.native.System.Data.SqlClient.sni/ It looks like ASP.NET core previously included SqlClient in Microsoft.AspNetCore.App, but then removed it in 3.0. That's the reason for this observed change. It was brought in by Microsoft.EntityFrameworkCore.SqlServer and Microsoft.Extensions.Caching.SqlServer, so the changes to these two components in 3.0 are what caused the removal of sni.dll from the AspNetCore shared framework. |
Is there a way to solve this? What is the permission recomendations for running a in proc asp.net core site in iis?
|
Hi @RomBrz Related question I had for you.. how to do you usually manage permissions for Dependent DLLs that are loaded by NuGet packages referenced? The change of package from System.Data.SqlClient > Microsoft.Data.SqlClient seems to be the motivation to remove SNI.dll from shared libs, as Microsoft.Data.SqlClient is now an independent library but also needs to reference SNI.dll from another NuGet package in order to work. |
Hi! @cheenamalhotra |
We're seeing the same issue with a .NET Core 3.1.101 project, using Microsoft.EntityFrameworkCore 3.1.2 and Microsoft.EntityFrameworkCore.SqlServer 3.1.2, built on Ubuntu 18.04 (both on my local machine and on Azure Pipelines Virtual Machines (link to machine spec: https://github.com/actions/virtual-environments/blob/master/images/linux/Ubuntu1804-README.md)). System.TypeInitializationException : The type initializer for 'Microsoft.Data.SqlClient.TdsParser' threw an exception.
----> System.TypeInitializationException : The type initializer for 'Microsoft.Data.SqlClient.SNILoadHandle' threw an exception.
----> System.DllNotFoundException : Unable to load shared library 'sni.dll' or one of its dependencies. In order to help diagnose loading problems, consider setting the LD_DEBUG environment variable: libsni.dll: cannot open shared object file: No such file or directory
at Microsoft.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, UInt32 waitForMultipleObjectsTimeout, Boolean allowCreate, Boolean onlyOneCheckConnection, DbConnectionOptions userOptions, DbConnectionInternal& connection)
at Microsoft.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal& connection)
at Microsoft.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal oldConnection, DbConnectionInternal& connection)
at Microsoft.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions)
at Microsoft.Data.ProviderBase.DbConnectionClosed.TryOpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions)
at Microsoft.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource`1 retry)
at Microsoft.Data.SqlClient.SqlConnection.OpenAsync(CancellationToken cancellationToken)
--- End of stack trace from previous location where exception was thrown ---
at Microsoft.EntityFrameworkCore.Storage.RelationalConnection.OpenDbConnectionAsync(Boolean errorsExpected, CancellationToken cancellationToken)
at Microsoft.EntityFrameworkCore.Storage.RelationalConnection.OpenDbConnectionAsync(Boolean errorsExpected, CancellationToken cancellationToken)
at Microsoft.EntityFrameworkCore.Storage.RelationalConnection.OpenAsync(CancellationToken cancellationToken, Boolean errorsExpected)
at Microsoft.EntityFrameworkCore.Update.Internal.BatchExecutor.ExecuteAsync(IEnumerable`1 commandBatches, IRelationalConnection connection, CancellationToken cancellationToken)
at Microsoft.EntityFrameworkCore.Update.Internal.BatchExecutor.ExecuteAsync(IEnumerable`1 commandBatches, IRelationalConnection connection, CancellationToken cancellationToken)
at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.StateManager.SaveChangesAsync(IList`1 entriesToSave, CancellationToken cancellationToken)
at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.StateManager.SaveChangesAsync(DbContext _, Boolean acceptAllChangesOnSuccess, CancellationToken cancellationToken)
at Microsoft.EntityFrameworkCore.SqlServer.Storage.Internal.SqlServerExecutionStrategy.ExecuteAsync[TState,TResult](TState state, Func`4 operation, Func`4 verifySucceeded, CancellationToken cancellationToken)
at Microsoft.EntityFrameworkCore.DbContext.SaveChangesAsync(Boolean acceptAllChangesOnSuccess, CancellationToken cancellationToken)
→ dotnet --info
.NET Core SDK (reflecting any global.json):
Version: 3.1.101
Commit: b377529961
Runtime Environment:
OS Name: ubuntu
OS Version: 18.04
OS Platform: Linux
RID: ubuntu.18.04-x64
Base Path: /usr/share/dotnet/sdk/3.1.101/
Host (useful for support):
Version: 3.1.1
Commit: a1388f194c
.NET Core SDKs installed:
2.2.402 [/usr/share/dotnet/sdk]
3.0.102 [/usr/share/dotnet/sdk]
3.1.101 [/usr/share/dotnet/sdk]
.NET Core runtimes installed:
Microsoft.AspNetCore.All 2.2.8 [/usr/share/dotnet/shared/Microsoft.AspNetCore.All]
Microsoft.AspNetCore.App 2.2.8 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 3.0.2 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 3.1.1 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.NETCore.App 2.2.8 [/usr/share/dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 3.0.2 [/usr/share/dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 3.1.1 [/usr/share/dotnet/shared/Microsoft.NETCore.App]
To install additional .NET Core runtimes or SDKs:
https://aka.ms/dotnet-download I tried to install Microsoft.Data.SqlClient 1.1.1 and the 2.0.0-preview1.20021.1, but that didn't help. Please let me know if I can help out by providing more information or trying out different packages. I have another project running with the same packages on Ubuntu, but without saving or reading data with EF Core, just using EF for migrations, and in that project we don't see any of the above issues. |
Hi @simonauner The driver shouldn't be loading sni.dll on Ubuntu in any case 😟 |
Yes, the other machine being the CI machine for Azure Pipelines (I linked the machine specs in my previous post). I'll try to setup a minimum reproducible repo and get back to you. |
I've tried to setup a basic repo that mimics the failing repo of ours, but everything seems to be working fine. My guess is that something we do in the DBContext setup messes it up. Can't find the issue at the moment though. |
Any update on this? Is there any fix? I am also receiving this error when I deploy my app:
|
I am also getting this error after we upgraded to EFCore 3.1.3 from EFCore 2.x (on local machines with iis express it is working fine .....only when I deploy it to server it fails) I've taken following steps so far Copied the sni.dll from C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App\2.1.16 But no luck so far Now it is We are having WebAPi project on .Net Fremework 4.7.1 , and the class libraries are .Net Standard 2.0 I also tried to install Microsoft.Data.SqlClient.Sni package even though it said not for direct consumption but that didn't help either |
Anyone able to resolve this issue? Having the same error which is blocking me to deploy my website.. |
Only thing that works in my case is #496 (comment) |
Man that's bad.. :/ |
If you have ftp access to your hosting account, you can use any ftp client e.g. Filezilla, right click |
Thanks a lot that helped! |
Not sure if this belongs here, I'm building small cross platform sql2csv utility everything is ok on mac os but on windows I receive: Error:
An assembly specified in the application dependencies manifest (sql2csv.deps.json) was not found:
package: 'Microsoft.Data.SqlClient.SNI.runtime', version: '2.0.0'
path: 'runtimes/win-x64/native/Microsoft.Data.SqlClient.SNI.pdb' builds are made with following flags: dotnet publish \
-c Release \
-p:PublishReadyToRun=true \
-p:PublishSingleFile=true \
-p:PublishTrimmed=true \
--self-contained true \
-r ${{ matrix.runtime }} my expectation of wondering if there is any known workaround, explicitly installing this library does not give any results, but builds without single file are working ok |
Hi @mac2000 Please view this issue in Dotnet SDK: dotnet/sdk#10523 |
Hello @cheenamalhotra thank you, indeed adding |
It's worked for me |
Hello, I have the same problem : migrating a .NET Core project from 2.2 to 3.1 with EF Core - not working because of DLL loading problem. In my case, the problem is indeed related to the new location of the sni.dll file - the antivirus stuff on my computer (McAfee Endpoint Security, managed by the IT security department) is forbidding any program to load .dll file from my user directory. You may check if you are in a similar case by looking at your antivirus logs or to the Windows Application logs - in my case, the logged messages are quite explicit. So now, I have to deal with the IT security department... |
We didn't pass this issue with IncludeSymbolsInSingleFile, but after enabling CopyLocalLockFileAssemblies. The scenario is that we are using EF 3.1 in some AWS Lambda projects and when we want to start the Lambda Mock Test Tool, then we can't because of the OP issue. We get the following message
|
After some time trying to figure out how to solve this and another potential problems, i would like to share what solved for me: I've tried to find something related to this officially, and seems like Microsoft tell us to use Read and Execute by default: "Read & execute permissions should be granted by default" https://docs.microsoft.com/en-us/aspnet/core/host-and-deploy/iis/?view=aspnetcore-3.1 With that, we changed the procedures to host DotNet Core applications, changing every project to use Read And Execute instead of Read, and with that the sni.dll (and other DLL) should not be a problem. Personally i don't agree with this "default" as i told early; Execute permission could give security problems, and DotNet Framework seems to work fine with Read only, but i cannot argue with official documentation... |
Closing issue as this is no-op for us. |
My issue was that I was building for Windows and not Linux
Probably related: |
We are using .NET Core in our applications, but with .NET Core 3.x.x we start to have problems that "sni.dll missing". Seems like when using it, the library put the sni.dll inside of the code itself, and this give me problems as we use the security recomendations to use permissions as little as possible (Read Only with Application Pool Identity), so the application in 3.x.x crashes as it try to execute the dll.
In .NET Core 2.x, when you install a Server Bundle, sni.dll comes with the Core as "shared dll", so any process could execute there. In .NET Core 3.x didn't come.
Workound: i copied the sni.dll from "C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App\2.2.8" to "C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App\3x.x" and the applications running .NET Core 3.x.x could run with "Read Only" permission on project folder (the same behavior that works with 2.x.x projects).
I already opened this issue in .NET Core git, but they told me that is a SQL thing
dotnet/aspnetcore#18266
The text was updated successfully, but these errors were encountered: