System.IO.FileNotFoundException with SqlClient

后端 未结 4 1478
旧时难觅i
旧时难觅i 2021-01-17 20:08

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

System.IO.FileNotFoundException: \'Could not load file or assembly \'System

相关标签:
4条回答
  • 2021-01-17 20:14

    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.

    0 讨论(0)
  • 2021-01-17 20:19

    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

    0 讨论(0)
  • 2021-01-17 20:19

    What I tried:

    I was also having the same error. I created a sample web api(2.0) which uses a .net standard 2.0 class library. In this library I am using Dapper and Dapper.Contrib and using their extension methods tried to query db. But was having the same error. I tried adding System.Data.SqlClient nuget package in the class library but it did not work. I am using VS2019 Community Edition. This has happened to me twice. So writing the exact scenario and solution that worked for me.

    What Worked:

    It was eventually resolved by removing System.Data.SqlClient nuget package from the class library and re-adding it in WebApi.

    Which is strange since class library is able to resolve dapper nuget package but not System.Data.SqlClient, from within itself.

    0 讨论(0)
  • 2021-01-17 20:30

    We resolved this by adding System.Data.SqlClient as a reference to our netstandard package, just using the nuget package manager. Once that was done Visual Studio did the rest in the Web solution.

    It seems like the dependencies are not all added to the netstandard library when adding a package like Dapper.

    0 讨论(0)
提交回复
热议问题