![](/img/trans.png)
[英]The type initializer for 'System.Data.SqlClient.TdsParser' threw an exception error while calling Stored Procedure from Azure function
[英]Azure Function 3.0.1 on netcore3.1 System.Data.SqlClient: The type initializer for 'System.Data.SqlClient.TdsParser' threw an exception
我使用的是最新版本的 azure 函数 3.0.1 和 .net core 3.1。 (以下问题看起来很熟悉,但它没有帮助我创建一个新的Azure 函数运行时异常,系统数据 sqlclient 异常的类型初始化程序,无法加载 DLL 'sni.dll' )
我想在这里提一下,同样的代码适用于 azure function 2 和 .net core 2.2
另一个重要信息是我正在使用 NHibernate,并且在执行 cfg.BuildSessionFactory() 时会出现此错误; 命令。
运行时错误是:
启动操作“3756a542-87f8-43dd-a977-fbf87c7597d1”期间发生主机错误。 [12/11/2019 5:17:42 AM] System.Data.SqlClient:“System.Data.SqlClient.TdsParser”的类型初始值设定项引发异常。 System.Data.SqlClient:“System.Data.SqlClient.SNILoadHandle”的类型初始值设定项引发异常。 System.Data.SqlClient:无法加载 DLL 'sni.dll' 或其依赖项之一:找不到指定的模块。 (0x8007007E)。
这是 .csproj 文件的一部分。
<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>
此外,添加了以下包而不是 system.data.sqlclient 作为解决方案,但都给出了相同的错误。
<PackageReference Include="Microsoft.Data.SqlClient" Version="1.1.0" />
我已经按照此链接https://dev.to/azure/develop-azure-functions-using-net-core-3-0-gcm 中的所有内容建立了一个新项目。
您是否尝试添加对 System.Data.SqlClient v4.4.0 的 nuget 引用。 这在解决缺少 sni.dll 中描述
有同样的问题。 阅读https://github.com/Azure/Azure-Functions/issues/1370 后。
添加到 local.settings.json 这个
"FUNCTIONS_V2_COMPATIBILITY_MODE": "真"
我将包从Microsoft.Data.SqlClient
更改为使用System.Data.SqlClient
并且错误消失了。
注意:我已将其更改为Microsoft.Data.SqlClient
因为System.Data.SqlClient
给出了相同的错误。 可能是包中有更新,或者最近的 Visual Studio 更新可能已修复它,我不确定。 但是进行此更改后错误消失了。 谢谢大家。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.