I'm having trouble bringing in class libraries which have recently been migrated to NetStandard2.0 into an old-style AspNet web application project (framework 4.7.2).
The updated assemblies reference NuGet package Microsoft.Data.SqlClient v5.1.0
When running, the app generates the following error trace when attempting to open a SQL connection:
The type initializer for 'Microsoft.Data.SqlClient.TdsParser' threw an exception.
The type initializer for 'Microsoft.Data.SqlClient.SNILoadHandle' threw an exception.
Unable to load DLL 'Microsoft.Data.SqlClient.SNI.dll': The specified module could not be found. (Exception from HRESULT: 0x8007007E)
Sure enough, there is no instance of Microsoft.Data.SqlClient.SNI.dll in the output bin folder - screenshot below - but there are instances of x64, x86 and arm64 dlls.
What's been tried:
Adding NuGet package Microsoft.Data.SqlClient v5.1.0 package directly into the web application project.
Located this resource which recommends that a .targets file (from the Microsoft.Data.SqlClient package) is explicitly referenced in the application's .csproj file, but doesn't elaborate on how to do that.
Located this question which asks almost the same question, and have attempted to incorporate the following tag in the application's .csproj file, but with no apparent effect or further diagnostic output:
<Target Name="_CopySNIFilesToWebProjectOutputDir" AfterTargets="CopySNIFiles" Condition="'$(WebProjectOutputDir)' != ''"> <Copy SourceFiles="@(SNIFiles)" DestinationFiles="@(SNIFiles -> '$(WebProjectOutputDir)\bin\%(RecursiveDir)%(Filename)%(Extension)')" /> </Target>
Specified x64 as target platform. No impact.
I'm now at a loss for further avenues to pursue. How do I get Microsoft.Data.SqlClient.SNI.dll into my application's bin folder?