efcore icon indicating copy to clipboard operation
efcore copied to clipboard

An exception of type 'System.DllNotFoundException' occurred in EntityFramework.Core.dll

Open giancarloa opened this issue 10 years ago • 7 comments

Hello... I am trying to run a simple test with EF7 but am getting the error below... what's strange is that earlier today the same test was working just fine... not sure what changed or what the problem may be... the code I am executing is simply:

var users = _dbc.Set().ToList();

where _dbc is a DbContext instance... for testing purposes I am trying to run this code inside an xunit unit test... the unit test project's profile is set to run using coreclr x64 rc update 1... what's strange is that I know this was working previously... I even examined the users variable above and it had the collection of objects from the database I was expecting... anyone have any ideas? thank you

An exception of type 'System.DllNotFoundException' occurred in EntityFramework.Core.dll but was not handled in user code

Additional information: Unable to load DLL 'C:\Users\giancarloa.dnx\packages\runtime.win7-x64.System.Data.SqlClient.sni\4.0.0-beta-23516\runtimes\win7-x64\native\sni.dll': The specified module could not be found. (Exception from HRESULT: 0x8007007E)

giancarloa avatar Feb 03 '16 04:02 giancarloa

one thing I forgot to mention above is that the file referenced by the error message does in fact exist on my machine... so again I am not sure why it's complaining it can't find something... some sort of dll version binding issue perhaps... not sure... and by the way not sure why when I pasted the above error message the path was changed... the correct path is C:\Users\giancarloa.dnx\packages\runtime.win7-x64.System.Data.SqlClient.sni\4.0.0-beta-23516\runtimes\win7-x64\native\sni.dll... not sure why the backslash before .dnx was removed... anyway... thanks

giancarloa avatar Feb 03 '16 04:02 giancarloa

one other thing i want to mention is that if i change my test project's profile to run using full .net framework, the code works fine... it's just when i run under netcore that the error takes place... although i want to stress this was working earlier when running under netcore... thanks

giancarloa avatar Feb 03 '16 04:02 giancarloa

There have been a few bug reports with these same symptoms but with slightly different root causes. Please check if your case matches any of the issues in this list and otherwise create a new issue at https://github.com/dotnet/corefx/issues.

it's just when i run under netcore that the error takes place

There is a simple explanation for that: in the standard desktop version of .NET there is no separate sni.dll that needs to be loaded but instead System.Data.dll is a mixed mode assembly that contains the native parts of SqlClient.

divega avatar Feb 03 '16 06:02 divega

Also check https://github.com/dotnet/corefx/issues/3760 which describes another possible cause and workaround (installing the Microsoft Visual C++ 2012 Redistributable). I have just edited the contents of that issue to include the name of the exception but it might not show up yet in the link I posted previously.

divega avatar Feb 03 '16 06:02 divega

@divega thanks... i will check it out...

giancarloa avatar Feb 03 '16 14:02 giancarloa

@divega thanks... it's working now for me... from the list of links you gave me the following one helped: https://github.com/dotnet/corefx/issues/5521... once I added the path to the coreclr to my user path environment variable, things started working... the bold piece below is what I added... I still don't understand though why this is necessary... my test project's profile is set to run coreclr x86... why does its path need to be in the user path environment variable? also, what happens when there are multiple dnx paths in the user path environment variable? which one wins? who actually chooses the path within the list of paths to use... this set up seems sort of fragile... anyway... i am good for now... thanks a lot!!!

C:\Users\giancarloa.dnx\runtimes\dnx-clr-win-x86.1.0.0-rc1-update1\bin;C:\Users\giancarloa.dnx\bin;C:\Users\giancarloa\AppData\Roaming\npm;C:\Users\giancarloa.dnx\runtimes\dnx-coreclr-win-x86.1.0.0-rc1-update1\bin

giancarloa avatar Feb 04 '16 00:02 giancarloa

@giancarloa Glad it helped.

I would lie if I said that I understand perfectly why it doesn't work :smile: The context I have is that this was confirmed to be a bug in DNX but we decided not to fix it because we are in the process of retiring DNX and replacing with .NET Core CLI. The scenario has been verified to work with .NET Core CLI (see https://github.com/dotnet/cli/issues/881) but there is still the outstanding issue of sni.dll depending on the Visual C++ runtime (https://github.com/dotnet/corefx/issues/3760).

divega avatar Feb 04 '16 00:02 divega