我在system.data.sqlclient版本4.7.0中使用aspnet core 3.0和azure函数v3预览当我尝试运行azure函数(在服务队列触发器和时间触发器上(时,它会给出以下错误:
"System"的类型初始值设定项。数据SqlClient。TdsParser"引发异常。"System"的类型初始值设定项。数据SqlClient。SNILoadHandle"引发异常。无法加载DLL"sni.DLL"或其依赖项之一:找不到指定的模块。
我尝试了以下链接中的解决方案,但没有成功:1.Azure功能-系统。数据此平台不支持SqlClient2.https://github.com/Azure/app-service-announcements-discussions/issues/9
我尝试将"Microsoft.Data.SqlClient"用于aspnetcore 3.0,但在Azure门户网站上运行Azure功能时仍会发生相同的异常。
请帮忙!
这是csproj文件
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp3.0</TargetFramework>
<AzureFunctionsVersion>v3-preview</AzureFunctionsVersion>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Sdk.Functions" Version="1.0.30-beta2" />
<PackageReference Include="runtime.native.System.Data.SqlClient.sni" Version="4.6.0" />
<PackageReference Include="System.Data.SqlClient" Version="4.7.0" />
</ItemGroup>
<ItemGroup>
<None Update="host.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="local.settings.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<CopyToPublishDirectory>Never</CopyToPublishDirectory>
</None>
</ItemGroup>
<!-- For publish --><!--
<ItemGroup>
<None Include="$(USERPROFILE).nugetpackages\microsoft.data.sqlclient1.0.19249.1runtimeswinlibnetcoreapp2.1microsoft.Data.SqlClient.dll">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>
--><!-- For local debug --><!--
<Target Name="CopyToBin" BeforeTargets="Build">
<Copy SourceFiles="$(USERPROFILE).nugetpackagesmicrosoft.data.sqlclient1.0.19249.1runtimeswinlibnetcoreapp2.1microsoft.Data.SqlClient.dll" DestinationFolder="$(OutputPath)bin" />
</Target>-->
<ItemGroup>
<None Include="$(USERPROFILE).nugetpackages\system.data.sqlclient4.7.0runtimeswinlibnetcoreapp2.1system.Data.SqlClient.dll">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>
<Target Name="CopyToBin" BeforeTargets="Build">
<Copy SourceFiles="$(USERPROFILE).nugetpackagessystem.data.sqlclient4.7.0runtimeswinlibnetcoreapp2.1system.Data.SqlClient.dll" DestinationFolder="$(OutputPath)bin" />
</Target>
</Project>
请确保您的azure函数在此链接中符合这些标准。
这里有一个由其他人提供的解决方法,将以下内容添加到.csproj:中
<Target Name="PostBuild" AfterTargets="PostBuildEvent">
<Exec Command="copy $(OutDir)$(ProjectName).deps.json $(OutDir)binfunction.deps.json" />
</Target>
<Target Name="PostPublish" BeforeTargets="Publish">
<Exec Command="copy $(PublishDir)$(ProjectName).deps.json $(PublishDir)binfunction.deps.json" />
</Target>
在csproj文件中添加以下代码对我很有效:
<Target Name="PostPublish" BeforeTargets="Publish">
<Exec Command="move $(PublishDir)runtimes $(PublishDir)bin" />
</Target>
这一行应该注意:<Exec Command="move $(PublishDir)runtimes $(PublishDir)bin" />
参考:github