runtime icon indicating copy to clipboard operation
runtime copied to clipboard

Opening SqlConnection results in DllNotFoundException (Unable to load sni.dll) in case of executing from Visual Studio

Open sady4850 opened this issue 10 years ago • 13 comments

works fine from command line

code

            var connection = new SqlConnection("valid connection string");
            connection.Open();

project.json:

{
  "version": "1.0.0-*",
  "description": "ConsoleApp10 Console Application",
  "authors": [ "sady4850" ],
  "tags": [ "" ],
  "projectUrl": "",
  "licenseUrl": "",

  "compilationOptions": {
    "emitEntryPoint": true
  },

  "dependencies": {
    "System.Data.SqlClient": "4.0.0-beta-23516"
  },

  "commands": {
    "ConsoleApp10": "ConsoleApp10"
  },

  "frameworks": {
     "dnxcore50": {
      "dependencies": {
        "Microsoft.CSharp": "4.0.1-beta-23516",
        "System.Collections": "4.0.11-beta-23516",
        "System.Console": "4.0.0-beta-23516",
        "System.Linq": "4.0.1-beta-23516",
        "System.Threading": "4.0.11-beta-23516"
      }
    }
  }
}

exception:


   at System.Runtime.Loader.AssemblyLoadContext.InternalLoadUnmanagedDllFromPath(String unmanagedDllPath)
   at System.Runtime.Loader.AssemblyLoadContext.LoadUnmanagedDllFromPath(String unmanagedDllPath)
   at Microsoft.Dnx.Runtime.Loader.LoadContext.LoadUnmanagedLibraryFromPath(String path)
   at Microsoft.Dnx.Runtime.Loader.PackageAssemblyLoader.LoadUnmanagedLibrary(String name)
   at Microsoft.Dnx.Host.LoaderContainer.LoadUnmanagedLibrary(String name)
   at Microsoft.Dnx.Host.DefaultLoadContext.LoadUnmanagedLibrary(String name)
   at Microsoft.Dnx.Runtime.Loader.LoadContext.LoadUnmanagedDll(String unmanagedDllName)
   at System.Runtime.Loader.AssemblyLoadContext.ResolveUnmanagedDll(String unmanagedDllName, IntPtr gchManagedAssemblyLoadContext)
   at System.Data.SqlClient.SNINativeMethodWrapper.SNIInitialize(IntPtr pmo)
   at System.Data.SqlClient.SNILoadHandle..ctor()
   at System.Data.SqlClient.SNILoadHandle..cctor()

SQL Client: Unable to load sni.dll (DllNotFoundException)

sady4850 avatar Jan 19 '16 19:01 sady4850

see also dotnet/runtime#16048

sady4850 avatar Jan 19 '16 20:01 sady4850

Erm. Isn't this a duplicate of the issue I had open at https://github.com/aspnet/EntityFramework/issues/4162 that got merged into https://github.com/dotnet/corefx/issues/5252 that got closed but got tracked into aspnet/dnx#3316 and dotnet/cli#881 ?

dan-dragan avatar Jan 19 '16 20:01 dan-dragan

Is this the main tracking issue? The few libs hitting this (runtime bindings?) are the biggest pain in RC1, I'd consider this high-priority for RC2.

NickCraver avatar Jan 22 '16 02:01 NickCraver

Please note that DNX is getting replaced by the new .NET CLI (https://github.com/dotnet/cli), so we should verify if this is still an issue when running on the .NET CLI. We are not fixing DNX specific issues at this point.

danroth27 avatar Jan 26 '16 16:01 danroth27

Is there any post explaining the hole thing about dnx and cli. I'm a little confused about what will survive, what will die and what will be modified. How do we test if this problem exists in net cli?

airomero avatar Jan 26 '16 18:01 airomero

You can get the latest .NET CLI build from http://dotnet.github.io.

danroth27 avatar Jan 26 '16 21:01 danroth27

I just verified that .NET CLI won't have this issue any more because the runtime will be set as local.

https://github.com/dotnet/cli/issues/881

kkurni avatar Jan 29 '16 02:01 kkurni

What do you mean with "the runtime will be set as local"? Local to the application??

airomero avatar Jan 29 '16 11:01 airomero

@kkurni Why are linking IIS publishing issue here ? This issue is not related to the IIS at all.

sady4850 avatar Jan 29 '16 11:01 sady4850

@airomero in Dotnet CLI, the runtime is published in the same folder (local) as the compiled application. this will make sure that the published runtime is used instead of installed runtime

In DNX, the runtime is published on different folder which need something to register this path to enviroment variables to use that runtime. (this can potentially conflict with the installed runtime.

kkurni avatar Jan 29 '16 16:01 kkurni

@sady4850 this could be the same issue as DNX always assume to use installed runtime which registered in your "path" environment variables.

I cannot repro this issue while debugging console app in visual studio. image

Here is my project.json image

Try to troubleshoot this in your machine.

  • Open Process Monitor to your console application.
  • Check which DNX runtime that visual studio open. (is it using the correct runtime ?)

image

  • Search for SNI.dll (Where Sni.dll is loaded ? Success /Fail ?)

image

  • Search for stringansi-l1 (Check whether api-ms-win-core-stringansi-l1-1-0.dll is loaded ?) It should api-ms-win-core-stringansi-l1-1-0.dll from dnx runtime instead of packages.

image

  • if it is failed to load stringansi-l1, check your environment variables. It should register dnx runtime path there.

image

If you still can't figure out, send me the screenshot of your process manager which shows when dnx is loaded, Sni.dll and stringansi.

kkurni avatar Jan 29 '16 17:01 kkurni

@kkurni ye, there wasn't dnx path in PATH. Still an open question why it is disappeared from there (because it worked and obviously I didn't remove it manually)

sady4850 avatar Jan 29 '16 18:01 sady4850

To find out why it works on console app (without VS Debugger), you can attach process monitor as well on console application without using VS debugger. (check where sni.dll and stringansi.dll is loaded).

it will be hard to answer why this path is disappeared. probably some other installation of other frameworks / version which override / remove this runtime path.

I will close this as we have the root cause why we get SNI.dll error. And The DNX is being retired in favor of the new dotnet CLI command line tools

kkurni avatar Jan 29 '16 19:01 kkurni