SNI.dll file locked when ASP.NET (Framework 4.8) App is running in IIS

See original GitHub issue

Describe the bug

The SNI.dll file is loaded/locked by IIS when using a Microsft.Data.SqlClient connection in a ASP.NET 4.8 Framework website but is not unloaded when the app is shutdown. Subsequent attempts to build or deploy the site are blocked by the error Unable to delete file “bin\x86\SNI.dll”. Access to the path ‘…\bin\x86\SNI.dll’ is denied. Every other dll in the bin folder can be deleted even while the web app is still running save for this one.

To reproduce

1.) Create an ASP.NET MVC website on the 4.8 Framework 2.) Add the Microsoft.Data.SqlClient package 3.) In the HomeController.Index method open a SqlConnection and execute an arbitrary command

using (var connection = new SqlConnection("<connection string here>"))
{
    connection.Open();
    new SqlCommand("SELECT 1", connection).ExecuteNonQuery();
}

4.) Cause the site to shutdown by modifying the web.config or stopping the debugger. 5.) The SNI.dll file remains locked and cannot be replaced or modified without shutting down IIS or the application pool associated with the website

Expected behavior

The SNI.dll should be unlocked (like the rest of the files in the bin folder) so that a site can be updated through deployment or build.

Further technical details

Microsoft.Data.SqlClient version: v1.1.0 .NET target: Framework 4.8 SQL Server version: SQL Azure Operating system: Windows 10 Professional / Windows Server 2016 Datacenter (Azure VM)

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:36
  • Comments:82 (24 by maintainers)

github_iconTop GitHub Comments

30reactions
vishnu4commented, Jan 2, 2020

I get that it happens when apps are active or running in IIS. i’m not debating that. I understand that the designs are very different as well, i’m not debating that either. I’m just saying my use cases are not edge or unique, and even though i don’t have a solution to this issue, i don’t think it should be closed or ignored.

The 2 places i see this issue are:

  • on deploy via azure devops, i’ve now added a ‘recycle app pool’ task, which runs fine, but SNI.dll was still seen as locked during some of my deploys (while it is trying to purge the bin directory). so either the recycle wasn’t good enough, or i need to change the task so that IIS is stopped entirely during the deployment process.
  • when i’m on my development machine I can run the app, work in it, and then rebuild again. 50% of the time my rebuild fails because the file is locked. this definitely makes development difficult if i have to add the extra step of recycling the app pool or restarting IIS between every build.

I understand i’m in .net framework, and that is a purgatory that i should try to get myself out of, but the move to use microsoft.data.sqlclient was part of that move for me, but it’s actually making the move harder because of these issues. I have a large monolith .net framework app and i am gradually moving projects towards .net standard. This gradual move is what is causing my issue apparently.

So the solution is that i can’t move gradually? I have to move everything to .net core immediately, all in one go without doing things in steps? That just doesn’t seem realistic, which is the only point i’m trying to make here. This issue is making development more difficult, and the only solution seems to be to move everything BACK to .net framework so i can use System.Data.SQLClient instead, which prevents me from ever really moving to .net core.

.Net core is the primary focus. Great, totally down with that. Shouldn’t that mean that aiding users from migrating from .Net Framework to .Net core should be important then?

13reactions
vishnu4commented, Jan 2, 2020

I’m surprised this issue is locked. while it might be ‘as it worked before’ with the previous version of sqlclient, it’s not really ideal behavior, right? recycling the app pool isn’t always reliable, and additionally I hit this issue frequently on my development box on just compiling.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Unable to load DLL 'sni.dll' - Entity Framework Core
When using Entity Framework Core in an ASP.Net Core application on Visual Studio 2017 I intermittently get the error "Unable to load 'sni.dll'....
Read more >
Unable to load DLL 'Microsoft.Data.SqlClient.SNI.x64.dll'
This method had worked with me if this file "Microsoft.Data.SqlClient.SNI.x86.dll" is not exists in this path: "C:\Program Files ...
Read more >
Unable to load DLL 'Microsoft.Data.SqlClient.SNI.x64.dll'
Hi , I am having an legacy vb.net application which is using .net 4.7.2. I replaced System.Data.Sqlclient with Microsoft.Data.
Read more >
bin files locked by IIS Worker Process.
I'm just going to https://localhost in Chrome to run the ASP.NET Core web application. After running the website (even without debugger attached), if...
Read more >
SqlClient troubleshooting guide - ADO.NET Provider for ...
Recommended Solution: Ensure "Execute" permissions are granted on the filesystem where native runtime libraries are loaded in the .NET Core ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

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