-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
SqlClient: Unable to load DLL 'sni.dll' #16905
Comments
@saurabh500 @YoungGah @corivera : blocking rc2 bug |
Looking into it. |
We are hitting it on aspnetci servers too. Win Server 2008 R2. I've attached a sample lockfile. project.lock.json |
@natemcmaster when did you start facing this issue? cc @ericstj |
We just noticed it this morning. SqlClient 4.1.0-rc2-23931 |
//cc @weshaggard I double checked the lock file and the packages and confirm that the DLL is correct bitness and references msvcrt.dll. @natemcmaster if you run depends on the SNI.dll on the machine that's failing it should show you what's missing. I'm reviewing the dependencies now against what I see in the project.lock.json to make sure we aren't missing some api-set dll. |
I double checked all the API set dependencies and they are satisfied. @schellap perhaps something wrong with how the host is setting up paths for PInvoke. |
This may also be part of it. From @BrennanConroy:
|
@natemcmaster, can you point me to the project that reproes it. |
I can consistently repo on a Win Server 2008 R2 box, but not my local machine. Contact me internally and I can point you to the right box.
cc @saurabh500 |
Could this be another problem with missing a redist? |
That DLL compiles against msvcrt.dll which isn't the redist CRT: it should be part of the OS. If you try depends.exe on the dll on the target machine it will tell you if anything is missing. |
@mrmeek What OS are you running your app on ? |
What is puzzling to me at this point is:
The last one contains the dir where the sni.dll is present. |
We can double check that one of these is causing the actual load failure using procmon. |
Here is the procmon dump on dotnet.exe. Not sure which needle in this haystack to look for. |
I think you need to monitor |
Could it the error be caused by one of these events? |
Looks like it, to troubleshoot try taking all the API set dlls and dropping them next to sni.dll and see if that fixes it. If it does, it seems to be an issue with the way the host is setting up the probing paths for native DLLs. |
Must be. The error went away when I moved |
I suppose that's one workaround. I was able to validate my specific suggestion as well by dumping all the API sets into @schellap it looks like the NATIVE_DLL_SEARCH_DIRECTORIES aren't being honored when locating dependencies of native DLLs. |
Taking @ericstj 's approach futher, if I copy only the |
That's just because your WS2008R2 machine happened to have the other API sets centrally installed via https://support.microsoft.com/en-us/kb/2999226. That update only contains a subset of the api set DLLs that CoreFx depends on and it is not an explicit pre-req AFAIK. We need the host/CLR to fix this problem generically, otherwise native dependencies across packages are broken. |
Should this issue be moved to cli then? cc @schellap |
Under the debugger,
|
@schellap shouldn't that probing list match NATIVE_DLL_SEARCH_DIRECTORIES? or at least contain a superset? |
@ericstj, why is this DLL not packaged with sxs sni.dll, if it needs it? If this app were to work on win7, right now, where is it even installed? NATIVE_DLL_SEARCH_DIRECTORIES is for CoreCLR, I don't think coreclr adds all native dlls to the windows load paths. Imagine how slow that would be. |
@schellap all of the corefx dlls, both managed and native, depend on the API set DLLs rather than directly on the OS implementation DLLs. We redistribute the API set DLLs downlevel in a single package and on newer OSes those are built in. You can think of this as just .NET Core providing a consistent native API surface across all the Windows OSes where we run (including phones). Consider that this is really no different than managed DLLs depending on other managed DLLs in other packages and CoreCLR handles that just fine. We cannot have the restriction that native dependencies must be packaged in the same package. That doesn't make any sense from a package author's perspective. We chatted and I think the perf hit is theoretical. We should measure before we make design decisions based on that. Additionally the perf hit is largely just for dev time where we are running from the package cache. In a published app everything will be in a single directory. In the portable app we'll only have a few directories for each fallback RID. To @natemcmaster's point, yes this is a CLI issue. We should move it. I'm not sure how to do that. |
@schellap Any idea on what changed and started causing this issue for Sni.dll in .Net CLI? Are there other Native dlls in corefx which need be aware of the Native dependency which need to be packaged with them? @ericstj My repro is on Windows 7 and I don't have the update you have mentioned. May be the API set were installed as part of another update. |
Re: @ericstj, @gkhanna79 just wanted to inform you that we would have to add all native dir paths to the windows load paths, because in portable apps the layout would look like:
bar.dll depends on foo.dll. @saurabh500, |
Why would a win81 component depend upon a Win7 component? Or, are they two different components in two packages where Win81 package has a dependency on Win7 package containing foo.dll? |
Correct. They are two packages where win81 has a dependency on win7 package. |
Implication of running from nuget cache. CC @weshaggard @piotrpMSFT |
@schellap I wanted to understand from EF's test perspective. I wanted to figure out why the tests started breaking now instead of earlier. I will follow up on this later. |
The issue at hand is a DLL's static references can come from different packages and different RIDs and hence different directories. An ugly hack for Windows is, we can simply modify process PATH (or do On Unix, is there such a solution? -- @davidfowl @anurse, this commit seems related and it preloads native binaries... aspnet/dnx#3060 |
Cc @moozzyk |
Thinking a bit more about this, this sounds more of a package composition implication. Shouldn't a native binary in a package be self-contained with its dependencies (unless they are installed in system paths) @davidfowl ? |
@gkhanna79 even if it is self-contained within the package, for Windows this is okay but the unix dynamic loader is not going to know about the package paths and sub folders. It has a very specific probe order. See this: http://man7.org/linux/man-pages/man3/dlopen.3.html
|
@schellap - in dnx we have a LoadContext and CoreClr calls us (LoadUnmanagedLibrary) each time they need to load a native lib. We know exact paths because we store them when we do package resolution when starting the app. |
@moozzyk Thanks. Finding the location of the native binary to pinvoke is supported by the host today. They key issue is that if the native binary being invoked to depends upon another native binary, how does that dependency get looked up by the OS loader? @davidfowl and I chatted about this as well. As your article calls out, there is no way to resolve that at runtime in a consistent manner for all platforms and requires the dependencies to be installed in shared locations of the OS where the OS loader can find them. |
@gkhanna79 - I couldn't find a good way of loading dependencies that are not global and not explicitly called out in the code (DllImport) on non-windows. |
@schellap @gkhanna79 can this issue be moved to /dotnet/cli for rc2? Are you waiting for any further data from @saurabh500 (my assumption is "no"). |
This issue is same as https://github.com/dotnet/cli/issues/2267. @schellap Should we close this as a dup? |
Closing as dup of https://github.com/dotnet/cli/issues/2267 |
This issue shouldn't be closed. asp.net 2.0 now has the issue. |
@foxjazz have you got repro and setup steps, etc? This may well be unrelated to this old issue above, except in symptoms. |
@foxjazz I solved it installing this NuGet package: runtime.native.System.Data.SqlClient.sni |
We are seeing a number of folks hitting the
Unable to load DLL 'sni.dll'
issue with the latest RC2 builds. Folks are hitting this when using EF Core but have confirmed that the issue exists when working directly with SQL Client too.See dotnet/efcore#4953 for a good description from someone hitting the issue.
cc @mrmeek who filed the above issue
The text was updated successfully, but these errors were encountered: