Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

System.IO.FileNotFoundException with SqlClient

Tags:

c#

.net

sqlclient

After fixing my problem as mentioned here I am getting the below exception

System.IO.FileNotFoundException: 'Could not load file or assembly 'System.Data.SqlClient, Version=4.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.'

My library is a .NET Standard 1.4 and the WebApp is .NET Framework 4.6.1

System.Data.SqlClient is version - 4.3.0 NuGet package. So I tried doing the below but in vain:

<dependentAssembly>
      <assemblyIdentity name="System.Data.SqlClient" culture="neutral" publicKeyToken="31bf3856ad364e35"/>
      <bindingRedirect oldVersion="4.1.0.0" newVersion="4.3.0.0"/>
</dependentAssembly>
like image 386
MantiCore Avatar asked Apr 20 '17 14:04

MantiCore


People also ask

What does System Io filenotfoundexception mean?

I hate to point out the obvious, but System.IO.FileNotFoundException means the program did not find the file you specified. So what you need to do is check what file your code is looking for in production.

What is filenotfoundexception in Microsoft Office?

Microsoft makes no warranties, express or implied, with respect to the information provided here. The exception that is thrown when an attempt to access a file that does not exist on disk fails. [ System.Serializable ] public class FileNotFoundException : System.

What is a string file not found exception?

File Not Found Exception (String, String, Exception) Initializes a new instance of the FileNotFoundException class with a specified error message, the file name that cannot be found, and a reference to the inner exception that is the cause of this exception.

What is the value of 0x80070002 for filenotfoundexception?

IOException FileNotFoundException uses the HRESULT COR_E_FILENOTFOUND which has the value 0x80070002. Initializes a new instance of the FileNotFoundException class with its message string set to a system-supplied message. Initializes a new instance of the FileNotFoundException class with the specified serialization and context information.


2 Answers

This sent me on a merry chase until I actually compared my project that didn't work, to one that did.

NUGET install for System.Data.SQLClient doesn't necessarily install the files of that name (.dll and .xml) - at least, it didn't for me.

I took those two files from the older project, put them in the bin for the newer, and this solved the problem.

like image 160
TheWizardOfTN Avatar answered Oct 16 '22 13:10

TheWizardOfTN


I guess you may have figured it out already but hope it would save someone precious time

In order to make everything work you would need to reference System.Data.SqlClient in WebApp .NET Framework 4.6.1 project that is referencing your .NET Standard Library. After that everything should work just fine.

Sounds like .NET Standard Library haven't grabbed with itself dependent library binary. There is nothing like "Copy Local" option in .NET Standard references so I don't see any way to check or set this behavior too

like image 23
Bogdan K Avatar answered Oct 16 '22 12:10

Bogdan K