I am using the latest version of azure functions 3.0.1 and .net core 3.1. ( The following question look familiar but it didn't help me so creating a new one Azure functions runtime exception, the type initializer for system data sqlclient excetion, Unable to load DLL 'sni.dll' )
I want to mention here that this same code works fine with azure function 2 and .net core 2.2
Another important information is I am using NHibernate and this error comes when executing cfg.BuildSessionFactory(); command.
The runtime error is:
A host error has occurred during startup operation '3756a542-87f8-43dd-a977-fbf87c7597d1'. [12/11/2019 5:17:42 AM] System.Data.SqlClient: The type initializer for 'System.Data.SqlClient.TdsParser' threw an exception. System.Data.SqlClient: The type initializer for 'System.Data.SqlClient.SNILoadHandle' threw an exception. System.Data.SqlClient: Unable to load DLL 'sni.dll' or one of its dependencies: The specified module could not be found. (0x8007007E).
Here is the part of .csproj file.
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<AzureFunctionsVersion>v3</AzureFunctionsVersion>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Azure.Functions.Extensions" Version="1.0.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="3.1.0" />
<PackageReference Include="Microsoft.NET.Sdk.Functions" Version="3.0.1" />
</ItemGroup>
Also, the following package was added instead of system.data.sqlclient as a solution but both give same error.
<PackageReference Include="Microsoft.Data.SqlClient" Version="1.1.0" />
I have followed everything from this link https://dev.to/azure/develop-azure-functions-using-net-core-3-0-gcm to set up a new project.
Have you tried to add a nuget reference to System.Data.SqlClient v4.4.0. This is described in Resolution to missing sni.dll
Had the same issue. after reading https://github.com/Azure/Azure-Functions/issues/1370.
add to the local.settings.json this
"FUNCTIONS_V2_COMPATIBILITY_MODE": "true"
I changed package from Microsoft.Data.SqlClient
to use System.Data.SqlClient
and the error gone.
Note: I had changed it to Microsoft.Data.SqlClient
as System.Data.SqlClient
was giving same error. May be there was an update in the package or recent Visual Studio updates may have fixed it, I am not sure. But the error gone by making this change. Thanks all.
User contributions licensed under CC BY-SA 3.0